Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b0Sk7-0005lF-2w for pgsql-bugs@arkaria.postgresql.org; Wed, 11 May 2016 11:55:55 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1b0Sk6-0006vh-M0 for pgsql-bugs@arkaria.postgresql.org; Wed, 11 May 2016 11:55:54 +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 1b0SjT-0006Ct-8x for pgsql-bugs@postgresql.org; Wed, 11 May 2016 11:55:15 +0000 Received: from mail-wm0-x22d.google.com ([2a00:1450:400c:c09::22d]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1b0SjP-0005qu-OH for pgsql-bugs@postgresql.org; Wed, 11 May 2016 11:55:14 +0000 Received: by mail-wm0-x22d.google.com with SMTP id g17so78099667wme.1 for ; Wed, 11 May 2016 04:55:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=rVFOXmwstSQ19io8do7pc/agXU41DFvNRXbSpppxtoU=; b=jMyNkJ5Kup8ypGWv1fZqQRJ5/lRfFSMuIxlnBMYM20zRIQeKlsJXvbb9i1fjIJix4r 7MjgYkkcxpcHlFSz1xWkZDJrImTmLsELWLPEeQHlU0uXoevgkBmr+3l2zx+8ToWEn/fx bfjhFqjnEnISq4uSBn5g2NSnXn4UrtV0jEGTTG1Lhh7CJvmFOkD3LIi/qZUA1ImC32Di 4DC8PetmVEgpTG4knWDz76woWrrKcXyUD4yMgZ+US5UjH4lioa1LcPwo/A8ixzV4hLZk gzyp7BhvoLcMiQY3w5TV3zwA+SRVKsSceui8K/mMnCtiMYJ77KOJFRZZFfYWk0tQhX9t 7EwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=rVFOXmwstSQ19io8do7pc/agXU41DFvNRXbSpppxtoU=; b=QMq3aTn0jzLzM0XGp359PtBOO8xrRiYM3Ro3l+E9L8mRYk6kxMsSiskyymqWMgsbsn EbHabhdxi/YySGyvQBN94KXTh8k5STOf3OJWCLnrWVgfZiJANzQ6+752QL9sfs62NfOX 3HRMx6JvGBZesasW3DpVMgn5/Ah01LJSm/Bygl51EjhPWSt0JtI/fZFX+332Nz5l7/HQ w+OoEvdTsJYe4csU1sBg+ZgimQ6+BM3dEOR0h3S6zKzxhAnbTFQeUELPQVsxet4DBwVH k+2B1KX5+bK5u+RZqwL4p/9kaoc5YRXay4SRR5eQx5fd4ubxT5i5pK1NdpEcqqtRn59u 6g4g== X-Gm-Message-State: AOPr4FX0HpZlhDevQmsn1LksjGCthC8bqxLnnu1q/GB7OWfCjNTiBwKs46jn4eREj+Xy4A== X-Received: by 10.194.153.65 with SMTP id ve1mr3374059wjb.106.1462967709251; Wed, 11 May 2016 04:55:09 -0700 (PDT) Received: from [192.168.1.144] (dsl-28-42.utaonline.at. [81.189.28.42]) by smtp.googlemail.com with ESMTPSA id i1sm4637413wjm.12.2016.05.11.04.55.07 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 11 May 2016 04:55:08 -0700 (PDT) Subject: Re: BUG #14107: Major query planner bug regarding subqueries and indices To: Tom Lane References: <20160421115638.22895.78902@wrigleys.postgresql.org> <69e376c7-6c2c-c96d-2ad6-3734affb59b7@gmail.com> <44df2e58-87f5-282c-9871-c735240c55e4@gmail.com> <1461406942121-5900147.post@n5.nabble.com> <3ac6f379-08f8-d1db-639f-2dc3075d2eb4@gmail.com> <1461610493986-5900430.post@n5.nabble.com> <629ecf23-b7b2-2d73-6792-150b111e83ab@gmail.com> <18635.1461892238@sss.pgh.pa.us> Cc: pgsql-bugs@postgresql.org From: Mathias Kunter Message-ID: Date: Wed, 11 May 2016 13:55:07 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.0 MIME-Version: 1.0 In-Reply-To: <18635.1461892238@sss.pgh.pa.us> Content-Type: text/plain; charset=iso-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Sorry for bumping this one more time, but I'd like to share some more real-life performance test results of using ANY(ARRAY(...)) instead of IN(...), hoping that you'd maybe still consider implementing such an optimization into the query planner. Since the test results indicate that the performance boost can really be massive on certain query types (factor 1000), I think that it'd really be worth the work. ===== Test setup ===== The tables "mb.release" and "mb.release_group" both contain about 1.5 million rows of real data, taken from the MusicBrainz database, and are of course properly indexed. All performance tests have been repeated a few times to be comparable. The test covers subqueries which return just a few rows and also subqueries which return more than 100000 rows. The queries test the performance of IN vs. ANY(ARRAY()) when used in different scenarios. For reference, the full query plans of all used queries are linked below. ===== Tested queries ===== 1) SELECT id FROM mb.release WHERE release_group IN (SELECT id FROM mb.release_group WHERE name = 'Bear'); 2) SELECT id FROM mb.release WHERE release_group IN (SELECT id FROM mb.release_group WHERE name < 'Bear'); 3) SELECT id FROM mb.release WHERE name = 'Tiger' OR release_group IN (SELECT id FROM mb.release_group WHERE name = 'Bear'); 4) SELECT id FROM mb.release WHERE name = 'Tiger' OR release_group IN (SELECT id FROM mb.release_group WHERE name < 'Bear'); 5) SELECT id FROM mb.release WHERE name = 'Tiger' AND release_group IN (SELECT id FROM mb.release_group WHERE name = 'Bear'); 6) SELECT id FROM mb.release WHERE name = 'Tiger' AND release_group IN (SELECT id FROM mb.release_group WHERE name < 'Bear'); ===== Test results ===== All numbers are given in milliseconds and show the total query time (planning + execution). ------------------------------------------- | Query | IN (...) | = ANY(ARRAY(...)) | ------------------------------------------- | 1 | 0.7 | 0.4 | | 2 | 6001.1 | 2517.8 | | 3 | 711.3 | 0.5 | | 4 | > 1000000.0 | 1962.6 | | 5 | 0.8 | 0.5 | | 6 | 0.9 | 492.7 | ------------------------------------------- Note: Query 4 using the IN operator has been canceled after running for more than 15 minutes. ===== Full query plans ===== For reference, all query plans of this performance test have been recorded using EXPLAIN (ANALYZE, BUFFERS). Please find them at http://pastebin.com/zymkbcSf -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs