pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Regression from 8.4 to 9.1.2/9.1.3: Optimizing filters on constants in unions
5+ messages / 2 participants
[nested] [flat]

* Regression from 8.4 to 9.1.2/9.1.3: Optimizing filters on constants in unions
@ 2012-03-03 00:58  Claus Stadler <cstadler@informatik.uni-leipzig.de>
  0 siblings, 2 replies; 5+ messages in thread

From: Claus Stadler @ 2012-03-03 00:58 UTC (permalink / raw)
  To: pgsql-bugs

Hi, not sure if this bug is already known, so sorry if it is ;)

Filtering a Union on constant custom type:
-------------------------------------------------------------------------------
DROP VIEW v;
DROP TABLE a;
DROP TABLE b;

DROP TYPE IF EXISTS mytype;
CREATE TYPE mytype AS ENUM ('x', 'y');

CREATE TABLE a (id INT);
CREATE TABLE b (id INT);

CREATE VIEW v AS SELECT t, id FROM (SELECT 'x'::mytype t, id FROM a 
UNION ALL SELECT 'y'::mytype t, id FROM b) c;

EXPLAIN SELECT * FROM v WHERE t = 'y';


PostgreSQL 8.4.10 on x86_64-pc-linux-gnu, compiled by GCC gcc-4.5.real 
(Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2, 64-bit
  Result  (cost=0.00..34.00 rows=2400 width=8)
    ->  Append  (cost=0.00..34.00 rows=2400 width=8)
          ->  Seq Scan on b  (cost=0.00..34.00 rows=2400 width=8)


PostgreSQL 9.1.2 on x86_64-pc-linux-gnu, compiled by gcc-4.6.real 
(Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1, 64-bit and also
PostgreSQL 9.1.3 on x86_64-pc-linux-gnu, compiled by gcc-4.6.real 
(Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1, 64-bit
  Result  (cost=0.00..80.00 rows=24 width=8)
    ->  Append  (cost=0.00..80.00 rows=24 width=8)
          ->  Seq Scan on a  (cost=0.00..40.00 rows=12 width=8)
                Filter: ('x'::mytype = 'y'::mytype)
          ->  Seq Scan on b  (cost=0.00..40.00 rows=12 width=8)
                Filter: ('y'::mytype = 'y'::mytype)

Regression: Expected result: That of 8.4.10
=====================================

Additionally, it is interesting that it does not work with text (not 
tested with other types such as integers):
-------------------------------------------------------------------------------

DROP VIEW v;
DROP TABLE a;
DROP TABLE b;

CREATE TABLE a (id INT);
CREATE TABLE b (id INT);

CREATE VIEW v AS SELECT t, id FROM (SELECT 'x' t, id FROM a UNION ALL 
SELECT 'y' t, id FROM b) c;

EXPLAIN SELECT * FROM v WHERE t = 'y';

PostgreSQL 8.4.10 on x86_64-pc-linux-gnu, compiled by GCC gcc-4.5.real 
(Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2, 64-bit
  Subquery Scan d  (cost=0.00..1107744.06 rows=150000 width=36)
    Filter: (d.t = 'y'::text)
    ->  Append  (cost=0.00..732744.04 rows=30000002 width=4)
          ->  Subquery Scan "*SELECT* 1"  (cost=0.00..244247.54 
rows=9999977 width=4)
                ->  Seq Scan on a  (cost=0.00..144247.77 rows=9999977 
width=4)
          ->  Subquery Scan "*SELECT* 2"  (cost=0.00..244248.96 
rows=10000048 width=4)
                ->  Seq Scan on b  (cost=0.00..144248.48 rows=10000048 
width=4)
          ->  Subquery Scan "*SELECT* 3"  (cost=0.00..244247.54 
rows=9999977 width=4)
                ->  Seq Scan on c  (cost=0.00..144247.77 rows=9999977 
width=4)


PostgreSQL 9.1.2 on x86_64-pc-linux-gnu, compiled by gcc-4.6.real 
(Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1, 64-bit and also
PostgreSQL 9.1.3 on x86_64-pc-linux-gnu, compiled by gcc-4.6.real 
(Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1, 64-bit
  Result  (cost=0.00..80.00 rows=24 width=36)
    ->  Append  (cost=0.00..80.00 rows=24 width=36)
          ->  Seq Scan on a  (cost=0.00..40.00 rows=12 width=36)
                Filter: ('x'::text = 'y'::text)
          ->  Seq Scan on b  (cost=0.00..40.00 rows=12 width=36)
                Filter: ('y'::text = 'y'::text)


Expected: Query optimizer should discard the scan as filter cannot be 
satisfied.
                Filter: ('x'::text = 'y'::text)
================================================================================




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Regression from 8.4 to 9.1.2/9.1.3: Optimizing filters on constants in unions
@ 2012-03-03 11:29  Claus Stadler <cstadler@informatik.uni-leipzig.de>
  0 siblings, 0 replies; 5+ messages in thread

From: Claus Stadler @ 2012-03-03 11:29 UTC (permalink / raw)
  To: pgsql-bugs

Hi, not sure if this bug is already known, so sorry if it is ;)

This is about an issue of the optimizer when having a union of selects 
that yield columns of constant value.

The first minimal example shows a regression, the second one a missed 
optimization.

Cheers,
Claus


Example 1: Filtering a Union on constant custom type:
-------------------------------------------------------------------------------
DROP VIEW v;
DROP TABLE a;
DROP TABLE b;

DROP TYPE IF EXISTS mytype;
CREATE TYPE mytype AS ENUM ('x', 'y');

CREATE TABLE a (id INT);
CREATE TABLE b (id INT);

CREATE VIEW v AS SELECT t, id FROM (SELECT 'x'::mytype t, id FROM a 
UNION ALL SELECT 'y'::mytype t, id FROM b) c;

EXPLAIN SELECT * FROM v WHERE t = 'y';


PostgreSQL 8.4.10 on x86_64-pc-linux-gnu, compiled by GCC gcc-4.5.real 
(Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2, 64-bit
  Result  (cost=0.00..34.00 rows=2400 width=8)
    ->  Append  (cost=0.00..34.00 rows=2400 width=8)
          ->  Seq Scan on b  (cost=0.00..34.00 rows=2400 width=8)


PostgreSQL 9.1.2 on x86_64-pc-linux-gnu, compiled by gcc-4.6.real 
(Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1, 64-bit and also
PostgreSQL 9.1.3 on x86_64-pc-linux-gnu, compiled by gcc-4.6.real 
(Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1, 64-bit
  Result  (cost=0.00..80.00 rows=24 width=8)
    ->  Append  (cost=0.00..80.00 rows=24 width=8)
          ->  Seq Scan on a  (cost=0.00..40.00 rows=12 width=8)
                Filter: ('x'::mytype = 'y'::mytype)
          ->  Seq Scan on b  (cost=0.00..40.00 rows=12 width=8)
                Filter: ('y'::mytype = 'y'::mytype)

Regression: Expected result: That of 8.4.10
=====================================

Example 2: Additionally, it is interesting that it does not work with 
text (not tested with other types such as integers):
-------------------------------------------------------------------------------

DROP VIEW v;
DROP TABLE a;
DROP TABLE b;

CREATE TABLE a (id INT);
CREATE TABLE b (id INT);

CREATE VIEW v AS SELECT t, id FROM (SELECT 'x' t, id FROM a UNION ALL 
SELECT 'y' t, id FROM b) c;

EXPLAIN SELECT * FROM v WHERE t = 'y';

PostgreSQL 8.4.10 on x86_64-pc-linux-gnu, compiled by GCC gcc-4.5.real 
(Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2, 64-bit
  Subquery Scan d  (cost=0.00..1107744.06 rows=150000 width=36)
    Filter: (d.t = 'y'::text)
    ->  Append  (cost=0.00..732744.04 rows=30000002 width=4)
          ->  Subquery Scan "*SELECT* 1"  (cost=0.00..244247.54 
rows=9999977 width=4)
                ->  Seq Scan on a  (cost=0.00..144247.77 rows=9999977 
width=4)
          ->  Subquery Scan "*SELECT* 2"  (cost=0.00..244248.96 
rows=10000048 width=4)
                ->  Seq Scan on b  (cost=0.00..144248.48 rows=10000048 
width=4)
          ->  Subquery Scan "*SELECT* 3"  (cost=0.00..244247.54 
rows=9999977 width=4)
                ->  Seq Scan on c  (cost=0.00..144247.77 rows=9999977 
width=4)


PostgreSQL 9.1.2 on x86_64-pc-linux-gnu, compiled by gcc-4.6.real 
(Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1, 64-bit and also
PostgreSQL 9.1.3 on x86_64-pc-linux-gnu, compiled by gcc-4.6.real 
(Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1, 64-bit
  Result  (cost=0.00..80.00 rows=24 width=36)
    ->  Append  (cost=0.00..80.00 rows=24 width=36)
          ->  Seq Scan on a  (cost=0.00..40.00 rows=12 width=36)
                Filter: ('x'::text = 'y'::text)
          ->  Seq Scan on b  (cost=0.00..40.00 rows=12 width=36)
                Filter: ('y'::text = 'y'::text)


Expected: Query optimizer should discard the scan as filter cannot be 
satisfied.
                Filter: ('x'::text = 'y'::text)
================================================================================




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Regression from 8.4 to 9.1.2/9.1.3: Optimizing filters on constants in unions
@ 2012-03-12 06:12  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Claus Stadler <cstadler@informatik.uni-leipzig.de>
  1 sibling, 0 replies; 5+ messages in thread

From: Tom Lane @ 2012-03-12 06:12 UTC (permalink / raw)
  To: Claus Stadler <cstadler@informatik.uni-leipzig.de>; +Cc: pgsql-bugs

Claus Stadler <cstadler@informatik.uni-leipzig.de> writes:
> Hi, not sure if this bug is already known, so sorry if it is ;)
> Filtering a Union on constant custom type:

This seems to be another unpleasant consequence of
http://git.postgresql.org/gitweb/?p=postgresql.git&a=commitdiff&h=57664ed25e5dea117158a2e663...

I'm starting to think we need to revert that in favor of some other
solution, though I have no idea what yet.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Regression from 8.4 to 9.1.2/9.1.3: Optimizing filters on constants in unions
@ 2012-03-16 17:17  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Claus Stadler <cstadler@informatik.uni-leipzig.de>
  1 sibling, 1 reply; 5+ messages in thread

From: Tom Lane @ 2012-03-16 17:17 UTC (permalink / raw)
  To: Claus Stadler <cstadler@informatik.uni-leipzig.de>; +Cc: pgsql-bugs

Claus Stadler <cstadler@informatik.uni-leipzig.de> writes:
> Filtering a Union on constant custom type:
> ...
> Expected: Query optimizer should discard the scan as filter cannot be 
> satisfied.

I've applied a patch for this.  Thanks for the report!

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Regression from 8.4 to 9.1.2/9.1.3: Optimizing filters on constants in unions
@ 2012-03-19 10:42  Claus Stadler <cstadler@informatik.uni-leipzig.de>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 5+ messages in thread

From: Claus Stadler @ 2012-03-19 10:42 UTC (permalink / raw)
  To: pgsql-bugs

Cool, thank you very much.

Cheers,
Claus

On 03/16/2012 06:17 PM, Tom Lane wrote:
> Claus Stadler<cstadler@informatik.uni-leipzig.de>  writes:
>> Filtering a Union on constant custom type:
>> ...
>> Expected: Query optimizer should discard the scan as filter cannot be
>> satisfied.
> I've applied a patch for this.  Thanks for the report!
>
> 			regards, tom lane
>




^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2012-03-19 10:42 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2012-03-03 00:58 Regression from 8.4 to 9.1.2/9.1.3: Optimizing filters on constants in unions Claus Stadler <cstadler@informatik.uni-leipzig.de>
2012-03-12 06:12 ` Tom Lane <tgl@sss.pgh.pa.us>
2012-03-16 17:17 ` Tom Lane <tgl@sss.pgh.pa.us>
2012-03-19 10:42   ` Claus Stadler <cstadler@informatik.uni-leipzig.de>
2012-03-03 11:29 Regression from 8.4 to 9.1.2/9.1.3: Optimizing filters on constants in unions Claus Stadler <cstadler@informatik.uni-leipzig.de>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox