Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Ya2zh-0007Qu-Qm for pgsql-bugs@arkaria.postgresql.org; Mon, 23 Mar 2015 14:06:17 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Ya2zg-0007wX-G6 for pgsql-bugs@arkaria.postgresql.org; Mon, 23 Mar 2015 14:06:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YZQNK-0005X4-Qq for pgsql-bugs@postgresql.org; Sat, 21 Mar 2015 20:52:06 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YZQNH-0000o6-9p for pgsql-bugs@postgresql.org; Sat, 21 Mar 2015 20:52:05 +0000 MIME-Version: 1.0 Subject: BUG #12888: Ignoring OPERATOR::RESTRICT=eqsel with subquery (pgsql-performance) To: pgsql-bugs@postgresql.org From: aleksmstu@mail.ru Date: Sat, 21 Mar 2015 20:51:12 +0000 Message-ID: <20150321205112.2576.67653@wrigleys.postgresql.org> X-Pg-Spam-Score: -1.2 (-) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 The following bug has been logged on the website: Bug reference: 12888 Logged by: Aleksandr Utorov Email address: aleksmstu@mail.ru PostgreSQL version: 9.4.1 Operating system: Win x86-32 Description: Hello, i create the operator === but the planner uses an index for a simple query only (e.g. SELECT * FROM t WHERE id === 1 ) In subquery the OPERATOR::RESTRICT=eqsel is ignoring, i.e no index used (e.g. SELECT * FROM t WHERE id === (SELECT 1) ) -- Full code -- -- Create the operator === with RESTRICT=eqsel CREATE FUNCTION is_not_distinct_from(anyelement, anyelement) RETURNS bool AS 'SELECT $1=$2 OR ($1 IS NULL AND $2 IS NULL);' LANGUAGE sql IMMUTABLE; CREATE OPERATOR === ( PROCEDURE=is_not_distinct_from(anyelement,anyelement), LEFTARG=anyelement, RIGHTARG=anyelement, COMMUTATOR= === ,RESTRICT=eqsel, JOIN=eqjoinsel, HASHES, MERGES); -- Create a test table. CREATE TABLE t ( id integer NOT NULL, CONSTRAINT t_pkey PRIMARY KEY (id) ); INSERT INTO t(id) SELECT generate_series(1, 100000); -- Test 1. SELECT * FROM t WHERE id === 1; 'Index Only Scan using t_pkey on t (cost=0.29..8.31 rows=1 width=4)' ' Index Cond: (id = 1)' -- OK (the best performance) -- Test 2. SELECT * FROM t WHERE id === ANY(ARRAY[1]); 'Seq Scan on t (cost=0.00..13943.00 rows=1 width=4)' ' Filter: (id === ANY ('{1}'::integer[]))' -- Low performace! -- Test 3. SELECT * FROM t WHERE id === (SELECT 1); 'Seq Scan on t (cost=0.01..26443.01 rows=1 width=8)' ' Filter: (id === $0)' ' InitPlan 1 (returns $0)' ' -> Result (cost=0.00..0.01 rows=1 width=0)' --Low performace! -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs