Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 353BF64FC3F for ; Thu, 25 Sep 2008 09:07:19 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 77314-05 for ; Thu, 25 Sep 2008 09:07:13 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from ppsw-6.csi.cam.ac.uk (ppsw-6.csi.cam.ac.uk [131.111.8.136]) by postgresql.org (Postfix) with ESMTP id BF05F64FC08 for ; Thu, 25 Sep 2008 09:07:13 -0300 (ADT) X-Cam-AntiVirus: no malware found X-Cam-SpamDetails: not scanned X-Cam-ScannerInfo: http://www.cam.ac.uk/cs/email/scanner/ Received: from flymine.sysbiol.cam.ac.uk ([131.111.60.120]:41127 helo=flymine.flymine.org) by ppsw-6.csi.cam.ac.uk (ppsw.cam.ac.uk [131.111.8.136]:25) with esmtp id 1Kipcj-0008TS-Jy (Exim 4.70) for pgsql-performance@postgresql.org (return-path ); Thu, 25 Sep 2008 13:07:09 +0100 Received: from host103 ([192.168.128.103] helo=aragorn.flymine.org ident=Debian-exim) by flymine.flymine.org with esmtp (Exim 4.12) id 1Kipcj-0003Vq-00 for pgsql-performance@postgresql.org; Thu, 25 Sep 2008 13:07:09 +0100 Received: from mnw21 (helo=localhost) by aragorn.flymine.org with local-esmtp (Exim 4.69) (envelope-from ) id 1Kipcj-0006YF-2k for pgsql-performance@postgresql.org; Thu, 25 Sep 2008 13:07:09 +0100 Date: Thu, 25 Sep 2008 13:07:09 +0100 (BST) From: Matthew Wakeling X-X-Sender: mnw21@aragorn.flymine.org To: pgsql-performance@postgresql.org Subject: Slow index Message-ID: User-Agent: Alpine 1.10 (DEB 962 2008-03-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; FORMAT=flowed; CHARSET=US-ASCII Content-ID: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200809/222 X-Sequence-Number: 31535 Hi all. I'm having an interesting time performance-wise with a set of indexes. Any clues as to what is going on or tips to fix it would be appreciated. My application runs lots of queries along the lines of: SELECT * from table where field IN (.., .., ..); There is always an index on the field in the table, but the table is not necessarily clustered on the index. There are six different indexes which the application hits quite hard, that I have investigated. These are: gene__key_primaryidentifier (index size 20MB) (table size 72MB) gene__key_secondaryidentifier (index size 20MB) (table size 72MB) ontologyterm__key_name_ontology (index size 2.5MB) (table size 10MB) protein__key_primaryacc (index size 359MB) (table size 1.2GB) publication__key_pubmed (index size 12MB) (table size 48MB) synonym__key_synonym (index size 3GB) (table size 3.5GB) These six indexes all perform very differently. These are the results from a few thousand queries on each index, from our application logs. Generally, the same value is not used more than once in all the queries. (1) (2) (3) (4) (5) gene__key_primaryidentifier 22 17 417 19 24.5 gene__key_secondaryidentifier 8.5 5.3 21 2.4 3.9 ontologyterm__key_name_ontology 6.5 6.5 9.4 1.4 1.4 protein__key_primaryacc 73 8.1 164 2.2 20 publication__key_pubmed 52 31 156 3.0 5.0 synonym__key_synonym 335 66 245 0.7 3.7 (1) - Average number of values in the IN list. (2) - Average number of rows returned by the queries. (3) - Average time taken to execute the query, in ms. (4) - Average time per value in the IN lists. (5) - Average time per row returned. All the queries are answered with a bitmap index scan on the correct index. I have also plotted all the log entries on an XY graph, with number of elements in the IN list against time taken, which is at http://wakeling.homeip.net/~mnw21/slow_index1.png. It is clear that the gene__key_primaryidentifier index runs a lot slower than some of the other indexes. The thing is, the table and the index are both small. The machine has 16GB of RAM, and its disc subsystem is a RAID array of 16 15krpm drives with a BBU caching RAID controller. The entire table and index should be in the cache. Why it is taking 20 milliseconds per value is beyond me. Moreover, the synonym index is MUCH larger, has bigger queries, and performs better. If we concentrate on just this index, it seems that some queries are answered very quickly indeed, while others are answered a lot slower. I have plotted just this one index on an XY graph, with two colours for values in the IN list and actual rows returned, which is at http://wakeling.homeip.net/~mnw21/slow_index2.png. It is clear that there is a gap in the graph between the slow queries and the fast queries. Is there something else going on here which is slowing the system down? The table is not bloated. There is quite heavy simultaneous write traffic, but little other read traffic, and the 16 spindles and BBU cache should take care of that quite happily. I don't think it's slow parsing the query, as it seems to manage on other queries in a millisecond or less. Any ideas welcome. Also, the mailing list server doesn't seem to be able to cope with image attachments. Matthew -- import oz.wizards.Magic; if (Magic.guessRight())... -- Computer Science Lecturer