X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 0E5783A4CC9 for ; Sat, 22 Jan 2005 00:51:23 +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 40714-09 for ; Sat, 22 Jan 2005 00:51:19 +0000 (GMT) Received: from fed1rmmtao01.cox.net (fed1rmmtao01.cox.net [68.230.241.38]) by svr1.postgresql.org (Postfix) with ESMTP id 90A653A4C8F for ; Sat, 22 Jan 2005 00:51:20 +0000 (GMT) Received: from [192.168.1.201] (really [68.111.226.8]) by fed1rmmtao01.cox.net (InterMail vM.6.01.04.00 201-2131-117-20041022) with ESMTP id <20050122005120.JDUS5137.fed1rmmtao01.cox.net@[192.168.1.201]> for ; Fri, 21 Jan 2005 19:51:20 -0500 Message-ID: <41F1A387.5040402@acm.org> Date: Fri, 21 Jan 2005 16:51:19 -0800 From: TJ O'Donnell Reply-To: tjo@acm.org User-Agent: Mozilla Thunderbird 0.9 (Windows/20041103) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: testing/predicting optimization using indexes Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200501/192 X-Sequence-Number: 19980 I have several questions reagaring the kind of increase in speed I can expect when I use a multi-column index. Here's what I've done so far. I've written some search functions which operate on character varying data used to represent molecular structures. We call this a Smiles string. I want to optimize the search using an index. As a test, I've created 9 integer columns in the tables containting atom counts, e.g. number of carbon atoms, oxygen, aromatic carbon, etc. I then made a multi-column index. Here are some samples times 1. When the table contains only smiles, no 9 integer columns and no index: Select count(smiles) from structure where oe_matches(smiles,'c1ccccc1CC(=O)NC'); 1313 rows in about 15 seconds. 2. When the table contains smiles and the 9 integer columns as an index: Select count(smiles) from structure where oe_matches(smiles,'c1ccccc1CC(=O)NC'); 1313 rows in about 20 seconds. 3. When the table contains smiles and the 9 integer columns as an index: Select smiles,id from structure where (nc,nn,no,ns,"n-arom-c","n-arom-n","n-arom-o","n-arom-s",nhalo) >= (3,1,1,0,6,0,0,0,0) and oe_matches(smiles,'c1ccccc1CC(=O)NC'); 1313 rows in about 7 seconds. I'm quite happy with the speedup in 3, but puzzled over the slowdown in 2. Here are my questions. 1. Why does the search slow down after I've created the extra columns and index, even when I don't ask to use the index in the SQL, as in 2. 2. Since I get such a nice speedup in 3, should I go to the trouble to create a new datatype (smiles) and define how it should be indexed in a way analogous to the 9 integer columns? In other words, could I expect an even greater speedup using a new datatype and index? Thanks, TJ