From: | Miroslav Šulc <miroslav(dot)sulc(at)startnet(dot)cz> |
---|---|
To: | PFC <lists(at)boutiquenumerique(dot)com> |
Cc: | John Arbash Meinel <john(at)arbash-meinel(dot)com>, PGSQL mailing list <pgsql-performance(at)postgresql(dot)org> |
Subject: | Re: How to read query plan |
Date: | 2005-03-14 09:17:44 |
Message-ID: | 423556B8.4020500@startnet.cz |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers pgsql-performance |
PFC wrote:
>
> Instead of a varchar(1) containing 'y' or 'n' you could use a BOOL
> or an integer.
Sure I could. The problem is our project still supports both MySQL and
PostgreSQL. We used enum('Y','N') in MySQL so there would be a lot of
changes in the code if we would change to the BOOL data type.
> Your query seems of the form :
>
> SELECT FROM main_table LEFT JOIN a lot of tables ORDER BY sort_key
> LIMIT N OFFSET M;
>
> I would suggest to rewrite it in a simpler way : instead of
> generating the whole result set, sorting it, and then grabbing a
> slice, generate only the ror id's, grab a slice, and then generate
> the full rows from that.
>
> - If you order by a field which is in main_table :
> SELECT FROM main_table LEFT JOIN a lot of tables WHERE
> main_table.id IN (SELECT id FROM main_table ORDER BY sort_key LIMIT N
> OFFSET M
> ) ORDER BY sort_key LIMIT N OFFSET M;
>
> - If you order by a field in one of the child tables, I guess you
> only want to display the rows in the main table which have this
> field, ie. not-null in the LEFT JOIN. You can also use the principle
> above.
>
> - You can use a straight join instead of an IN.
Do you mean something like this?
SELECT Table.IDPK, Table2.varchar1, Table2.varchar2, ...
FROM Table
LEFT JOIN many tables
INNER JOIN Table AS Table2
Miroslav
Attachment | Content-Type | Size |
---|---|---|
miroslav.sulc.vcf | text/x-vcard | 387 bytes |
From | Date | Subject | |
---|---|---|---|
Next Message | pgsql | 2005-03-14 12:38:20 | Re: signed short fd |
Previous Message | Greg Stark | 2005-03-14 09:13:23 | Re: [BUGS] We are not following the spec for HAVING without GROUP |
From | Date | Subject | |
---|---|---|---|
Next Message | Qingqing Zhou | 2005-03-14 09:26:55 | Re: column name is "LIMIT" |
Previous Message | Miroslav Šulc | 2005-03-14 09:09:38 | Re: How to read query plan |