Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bFn2d-00067d-1b for pgsql-performance@arkaria.postgresql.org; Wed, 22 Jun 2016 18:38:23 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bFn2c-0006y7-KE for pgsql-performance@arkaria.postgresql.org; Wed, 22 Jun 2016 18:38:22 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bFn0v-00034k-Ho for pgsql-performance@postgresql.org; Wed, 22 Jun 2016 18:36:37 +0000 Received: from mail-vk0-x22d.google.com ([2607:f8b0:400c:c05::22d]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bFn0r-0006XG-V1 for pgsql-performance@postgresql.org; Wed, 22 Jun 2016 18:36:37 +0000 Received: by mail-vk0-x22d.google.com with SMTP id u64so73881622vkf.3 for ; Wed, 22 Jun 2016 11:36:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=BxnS9l4IaW3nXmGa60F5gZr+DCtopXljNAtbByjk800=; b=TpJMBuZTW51UthfsR9Zo2eOQuOD9aM2MmJGERXhXW2NiF7Iw0Y/1C8Ieh5cL/4Jg2O gLqx7pWo6YqjvojK0zQbOe2kTKe0bx/vhqzYyhGmnIYFoCNnn5lVZwK13+JrJCqAR4JY 8ugk0zm4biuHVf58QsAFlcamMXE8NTeJokkCUyEXSR3KApJr+Z94OeOEbCS9u/SW4rJ+ IX2bZPz26TnJwkCvSMPAZHERCHJdluNbxxTzVrznHELXr60ZvuOguURe5k1bCahGs5/N uyNqzfV820UsC7rmFIUGIvvbV/cIhqxAM4aYQeSHE3N0Y/ozCFS1BFAz9HuoGiS9/FJK dCuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=BxnS9l4IaW3nXmGa60F5gZr+DCtopXljNAtbByjk800=; b=XMopuFFQXM4xoZX1rUWyzwo1rFHZ9UOEhwKPr6sVIpoFRObhkqA/umEESmT9IolN+1 9xb0fE0IE+FQwTANKgznlSuBEDNJ/CZc3RFGP3RjMg0+j3G/8ew6QPeaz72HRFT+Lzpz 5hohLxtNI6XwvsJ9L0F5e2lIXebnIdMxwdcG9rTPJJKN7qXK2iAZLXZiJXopS0Bvuaal TTdImaN2LG4qFgtQsAEExQHfpabBMpmeVFVX8XftQra9SYCmvA0ROoceNY5/UuCGRwHE nKmsaJRyp3Ne1sEewf1BzlssTWRyj7LZS/fp/jA4GRH7/I1smaUn6DqJ6kzacdtuKKHR fmqA== X-Gm-Message-State: ALyK8tLYRp8dwGRioG0M1tPeya0/qC9Qi7tiJuzlBL+DZ29PXEdLvzYQEIMf/+cKnaJfCF+ufZZ40oyk9aYZfw== X-Received: by 10.31.47.85 with SMTP id v82mr12797243vkv.140.1466620591923; Wed, 22 Jun 2016 11:36:31 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.131.204 with HTTP; Wed, 22 Jun 2016 11:36:31 -0700 (PDT) In-Reply-To: References: From: Jeff Janes Date: Wed, 22 Jun 2016 11:36:31 -0700 Message-ID: Subject: Re: Can't get two index scans To: Craig James Cc: "pgsql-performance@postgresql.org" Content-Type: text/plain; charset=UTF-8 X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org On Wed, Jun 22, 2016 at 9:03 AM, Craig James wrote: > I'm working with a third-party plugin that does chemistry. Out of personal/professional curiosity, which one are you using, if that can be disclosed? .... > Notice that it doesn't use the i_version_smiles index at all, but instead > applies the very expensive filter |>| to all 1% of the database. You have to tell the database that |>| is very expensive, by setting the COST of the function which it invokes. You can get the name of the function with: select oprcode from pg_operator where oprname ='|>|' ; (taking care for schema and overloading, etc.) I would set the COST to at least 1000, probably more. > So instead > of getting a 100x speedup, we only get a 3x speedup, about 30x worse that > what is theoretically possible. > > The production database is about 50x larger than this test database. > > Maybe I misunderstand what's possible with indexes, but it seems to me that > it could first do the pk_version index scan, and then use the results of > that to do a limited index-scan search using the i_version_smiles index. Is > that not possible? I don't think it can do that. What it can do is run each index scan to completion as a bitmap index scan, and then AND the bitmaps together. You might be able to build a multiple column index on (smiles, version_id) and have it do the right thing automatically. Whether that is possible, and if so how effective it will actually be, would depend on the implementation details of |>|. My gut feeling is that it would not work well. You could partition your data on version_id. Then it would keep a separate smiles index on each partition, and would only consult those indexes which can possibly contain (according to the CHECK constraints) the version_ids of interest in the query. Also, if you tune your system using benzene, you will be probably arrive at a place not optimal for more realistic queries. Cheers, Jeff -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance