Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 99531EDF370 for ; Tue, 22 May 2012 22:13:19 -0300 (ADT) Received: from mahout.postgresql.org ([98.129.198.123]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SX08c-0000dy-22 for pgsql-bugs@postgresql.org; Wed, 23 May 2012 01:13:18 +0000 Received: from [204.145.124.246] (helo=wrigleys.postgresql.org) by mahout.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SX08P-00008M-9R for pgsql-bugs@postgresql.org; Wed, 23 May 2012 01:13:05 +0000 Received: from www-data by wrigleys.postgresql.org with local (Exim 4.72) (envelope-from ) id 1SX08O-00085J-HA for pgsql-bugs@postgresql.org; Wed, 23 May 2012 01:13:04 +0000 Date: Wed, 23 May 2012 01:13:04 +0000 Message-Id: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #6662: Database do not push condition to subquery, test case for bug 6658 To: pgsql-bugs@postgresql.org From: maxim.boguk@gmail.com X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201205/162 X-Sequence-Number: 33133 The following bug has been logged on the website: Bug reference: 6662 Logged by: Maxim Boguk Email address: maxim.boguk@gmail.com PostgreSQL version: 9.1.3 Operating system: Linux Description: = I managed create simple self-contained test case for 6658. create table test as select * from generate_series(1,100000) as g(val); create index test_val_special on test((val || '')); analyze test; select count(*) from test; --ok --index scan explain analyze SELECT val FROM test WHERE (val || '')=3D'something'; QUERY PLAN ---------------------------------------------------------------------------= -------------------------------------------- Index Scan using test_val_special on test (cost=3D0.01..8.29 rows=3D1 wid= th=3D4) (actual time=3D0.011..0.011 rows=3D0 loops=3D1) Index Cond: (((val)::text || ''::text) =3D 'something'::text) Total runtime: 0.038 ms --not ok --seq scan on 9.1.3 explain analyze SELECT val = FROM ( SELECT val, (val || '') AS search_string FROM test ) AS t1 WHERE search_string=3D'something'; QUERY PLAN ---------------------------------------------------------------------------= --------------------------------------- Subquery Scan on t1 (cost=3D0.00..3443.00 rows=3D500 width=3D4) (actual time=3D47.076..47.076 rows=3D0 loops=3D1) Filter: (t1.search_string =3D 'something'::text) -> Seq Scan on test (cost=3D0.00..2193.00 rows=3D100000 width=3D4) (ac= tual time=3D0.012..34.949 rows=3D100000 loops=3D1) Total runtime: 47.091 ms --the same second query on 8.3.13 --plan correct QUERY PLAN ---------------------------------------------------------------------------= -------------------------------------------- Index Scan using test_val_special on test (cost=3D0.01..8.29 rows=3D1 wid= th=3D4) (actual time=3D0.004..0.004 rows=3D0 loops=3D1) Index Cond: (((val)::text || ''::text) =3D 'something'::text) Total runtime: 0.018 ms Kind Regards, Maksym