dbTalk Databases Forums  

Partition view optimization

comp.databases.postgresql.questions comp.databases.postgresql.questions


Discuss Partition view optimization in the comp.databases.postgresql.questions forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Stacy White
 
Posts: n/a

Default Partition view optimization - 05-15-2004 , 09:38 PM






I vaguely remember seeing that PostgresSQL optimized selects on certain
UNION ALL statements, so that given:

CREATE VIEW orders AS
SELECT '2003-01' as period, * FROM orders_2003_01
UNION ALL
SELECT '2003-02' as period, * FROM orders_2003_02

then

SELECT * FROM orders WHERE period = '2003-01'

would do a full table scan only on the orders_2003_01 table.

But I didn't see this optimization while I was running some tests against
7.4.2.

Am I missing something now? Or am I just mis-remembering Postgres'
behavior?



Reply With Quote
  #2  
Old   
Stacy White
 
Posts: n/a

Default Re: Partition view optimization - 05-19-2004 , 10:13 PM






I see now that the partition view optimization kicks in when I explicitly
cast the period to varchar:

CREATE VIEW orders AS
SELECT '2003-01'::varchar as period, * FROM orders_2003_01
UNION ALL
SELECT '2003-02'::varchar as period, * FROM orders_2003_02

Fair enough, although I'm a little puzzled as to why the plan is different
when the 'period' column is a 'varchar' rather than a 'text'.



"Stacy White" <harsh (AT) computer (DOT) org> wrote

Quote:
I vaguely remember seeing that PostgresSQL optimized selects on certain
UNION ALL statements, so that given:

CREATE VIEW orders AS
SELECT '2003-01' as period, * FROM orders_2003_01
UNION ALL
SELECT '2003-02' as period, * FROM orders_2003_02

then

SELECT * FROM orders WHERE period = '2003-01'

would do a full table scan only on the orders_2003_01 table.

But I didn't see this optimization while I was running some tests against
7.4.2.

Am I missing something now? Or am I just mis-remembering Postgres'
behavior?





Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.