X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 537455636B for ; Mon, 14 Mar 2005 09:17:50 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 39155-06 for ; Mon, 14 Mar 2005 09:17:41 +0000 (GMT) Received: from sranda.klamovka.kosire.czf (unknown [82.113.63.66]) by svr1.postgresql.org (Postfix) with ESMTP id 354BF567AF for ; Mon, 14 Mar 2005 09:17:35 +0000 (GMT) Received: (qmail 17412 invoked from network); 14 Mar 2005 10:17:37 +0100 Received: from fordfrog.klamovka.kosire.czf (HELO ?192.168.11.101?) (10.15.70.18) by smtp.klamovka.kosire.czf with AES256-SHA encrypted SMTP; 14 Mar 2005 10:17:37 +0100 Message-ID: <423556B8.4020500@startnet.cz> Date: Mon, 14 Mar 2005 10:17:44 +0100 From: =?ISO-8859-15?Q?Miroslav_=A6ulc?= Organization: StartNet s.r.o. User-Agent: Mozilla Thunderbird 1.0 (X11/20041208) X-Accept-Language: en-us, en MIME-Version: 1.0 To: PFC Cc: John Arbash Meinel , PGSQL mailing list Subject: Re: How to read query plan References: <42345D24.8070104@startnet.cz> <4234692E.3050802@arbash-meinel.com> <42347407.2000202@startnet.cz> <42347D5E.9000900@arbash-meinel.com> <42348F54.1000408@startnet.cz> <423493E5.6040203@arbash-meinel.com> <42355249.8090101@startnet.cz> In-Reply-To: X-Enigmail-Version: 0.89.5.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: multipart/mixed; boundary="------------080901070901040409070600" X-Virus-Scanned: by amavisd-new at hub.org X-Archive-Number: 200503/255 X-Sequence-Number: 10960 This is a multi-part message in MIME format. --------------080901070901040409070600 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit 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 --------------080901070901040409070600 Content-Type: text/x-vcard; charset=utf-8; name="miroslav.sulc.vcf" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="miroslav.sulc.vcf" begin:vcard fn;quoted-printable:Miroslav =C5=A0ulc n;quoted-printable:=C5=A0ulc;Miroslav org:StartNet s.r.o. adr;quoted-printable;quoted-printable:;;Vrchlick=C3=A9ho 161/5;Praha 5;;150 00;=C4=8Cesk=C3=A1 republika email;internet:miroslav.sulc@startnet.cz title:CEO tel;work:+420 257 225 602 tel;cell:+420 603 711 413 x-mozilla-html:TRUE url:http://www.startnet.cz version:2.1 end:vcard --------------080901070901040409070600--