Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WV0Km-0007J3-2m for pgsql-bugs@arkaria.postgresql.org; Tue, 01 Apr 2014 15:10:40 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WV0Kl-0005Ts-IZ for pgsql-bugs@arkaria.postgresql.org; Tue, 01 Apr 2014 15:10:39 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WUsRa-0000JW-6d for pgsql-bugs@postgresql.org; Tue, 01 Apr 2014 06:45:10 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WUsRS-0004Q5-Pz for pgsql-bugs@postgresql.org; Tue, 01 Apr 2014 06:45:09 +0000 MIME-Version: 1.0 Subject: BUG #9817: Broken index detection in case of functions with variadic array parameters To: pgsql-bugs@postgresql.org From: dmitry-ryabov@mail.ru Date: Tue, 01 Apr 2014 06:44:09 +0000 Message-ID: <20140401064409.342.76410@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: 9817 Logged by: Dmitry Ryabov Email address: dmitry-ryabov@mail.ru PostgreSQL version: 9.3.4 Operating system: Any Description: -- HOW REPRODUCE: CREATE TABLE test ( id INTEGER NOT NULL, value TEXT NOT NULL, PRIMARY KEY(id) ); -- just test function CREATE FUNCTION test_value_func ( text, variadic text [] ) RETURNS bigint AS $body$ select sum(position(unnest in $1)) from unnest($2) $body$ LANGUAGE 'sql' IMMUTABLE CALLED ON NULL INPUT SECURITY INVOKER; truncate test; insert into test select generate_series(1, 1000000), md5(random()::text); CREATE INDEX test_idx ON public.test USING btree ((test_value_func(value, 'a', 'b'))); -- index scan used select * from test where test_value_func(value, 'a', 'b') > 60; DROP INDEX test_idx; -- but after restore from backup index created like this CREATE INDEX test_idx ON public.test USING btree ((test_value_func(value, VARIADIC ARRAY['a'::text, 'b'::text]))); -- BUG! index scan isn't used select * from test where test_value_func(value, 'a', 'b') > 60; -- index scan used select * from test where test_value_func(value, VARIADIC ARRAY['a'::text, 'b'::text])>60 DROP INDEX test_idx; CREATE INDEX test_idx ON public.test USING btree ((test_value_func(value, 'a', 'b'))); -- index scan used select * from test where test_value_func(value, 'a', 'b') > 60; -- BUG! index scan isn't used select * from test where test_value_func(value, VARIADIC ARRAY['a'::text, 'b'::text])>60 -- affected version: 9.3.4 -- not affected version: 9.1.13 - index scan used in both cases DROP TABLE test; DROP FUNCTION test_value_func(text, variadic text []); -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs