Dustin Sallings <[EMAIL PROTECTED]> writes:
>       The following view creates the illusion of the old ``single-table'' 
> model:

> create view samples as
>      select * from samples_1999
>   union  select * from samples_2000
>   union  select * from samples_2001
>   union  select * from samples_2002
>   union  select * from samples_2003
>   union  select * from samples_2004

You really, really, really want to use UNION ALL not UNION here.

>       OK, now that that's over with, I have this one particular query that I 
> attempt to run for a report from my phone that no longer works because 
> it tries to do a table scan on *some* of the tables.  Why it chooses 
> this table scan, I can't imagine.

Most of the problem here comes from the fact that "current_date - 7"
isn't reducible to a constant and so the planner is making bad guesses
about how much of each table will be scanned.  If possible, do the date
arithmetic on the client side and send over a simple literal constant.
If that's not practical you can fake it with a mislabeled IMMUTABLE
function --- see the list archives for previous discussions of the
same issue.

                        regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]

Reply via email to