Re: How to speed up product code and subcode match

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrus <kobruleht2(at)hot(dot)ee>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to speed up product code and subcode match
Date: 2023-05-23 14:00:25
Message-ID: 908933.1684850425@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Andrus <kobruleht2(at)hot(dot)ee> writes:
> Product table as both main products and subproducts with sizes. Size is
> separated by main product code always by / character:

>     SHOE1-BLACK
>     SHOE1-BLACK/38
>     SHOE1-BLACK/41
>     SHOE1-BLACK/42
>     SHOE1-BLACK/43
>     SHOE2/XXL
>     SHOE2/L

You could probably have devised a worse data representation if
you really tried, but it would have taken some effort. Separate
the product code and size into two columns --- if there's somebody
who really wants to see them in the above format, give them a
view or generated column. Then instead of the impossible-to-optimize
queries you showed, you could do something like

select toode.toode , n2, n3, n4
from toode, vordlusajuhinnak
where toode.toode = vordlusajuhinnak.toode;

Anytime you're trying to join two tables on something that isn't
a plain equality condition (or ANDed conditions), you're in for
a world of hurt.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andrus 2023-05-23 14:26:12 Re: How to speed up product code and subcode match
Previous Message Andrus 2023-05-23 13:38:30 Re: How to speed up product code and subcode match