Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id A598F475C5F for ; Wed, 22 Jan 2003 03:54:54 -0500 (EST) Received: from mail2.itxmarket.com (fw.itxmarket.com [213.11.40.109]) by postgresql.org (Postfix) with ESMTP id E519A475BC3 for ; Wed, 22 Jan 2003 03:54:53 -0500 (EST) Received: from freebsdcluster.net (mich2.itxmarket.com [192.168.2.26]) by mail2.itxmarket.com (Postfix) with ESMTP id D567437CA2 for ; Wed, 22 Jan 2003 09:54:54 +0100 (CET) Received: by freebsdcluster.net (Postfix, from userid 1000) id B3A0C3B943E; Wed, 22 Jan 2003 09:54:54 +0100 (CET) Date: Wed, 22 Jan 2003 09:54:54 +0100 From: Michael Hostbaek To: pgsql-sql@postgresql.org Subject: optimal sql Message-ID: <20030122085454.GA55124@mich2.itxmarket.com> Mail-Followup-To: Michael Hostbaek , pgsql-sql@postgresql.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-PGP-Key: http://www.freebsdcluster.org/~mich/ User-Agent: Mutt/1.5.3i X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/324 X-Sequence-Number: 11189 Hi, I am running postgresql 7.2.3 on a test server (with potential of becoming my production server). On the server I have a perl script, that is grabbing some data from a inventory database (local) - with some subselects. The query is like this: my $sth = $ppdb->prepare(" select partno, create_date, mfg, condition, gescode, qty, cmup,(SELECT partno_main FROM partno_lookup where partno_lookup.partno_alias ilike (?|| inventory.partno ||?) and mfg ilike ? limit 1) as partno_main, (SELECT subcat FROM partno_lookup where partno_lookup.partno_alias ilike (?|| inventory.partno ||?) and mfg ilike ? limit 1) as subcat, (SELECT key_search FROM partno_lookup where partno_lookup.partno_alias ilike (?|| inventory.partno ||?) and mfg ilike ? limit 1) as key_search, (SELECT text_desc FROM descriptions where descriptions.partno=(SELECT partno_main FROM partno_lookup where partno_lookup.partno_alias ilike (?|| inventory.partno ||?) and mfg ilike ? limit 1) limit 1) as descri from inventory where mfg ilike ? and ? < create_date $refurbed order by key_search, subcat, partno_main, status DESC "); It takes quite a while for the query to get processed - and the script to return my values. The inventory table has approx. 23000 records - and the partno_lookup has approx. 1100. Is there anyway I can optimize the sql - og perhaps optimize my postgresql db settings ? ( I am running my postgresql on FreeBSD, on a fairly adequite machine with 1GB RAM) I look forward to any pointers or hints you might have. Thanks. /mich -- Best Regards, Michael Landin Hostbaek FreeBSDCluster.org - an International Community */ PGP-key available upon request /*