Re: inconsistent/weird index usage
От | Tom Lane |
---|---|
Тема | Re: inconsistent/weird index usage |
Дата | |
Msg-id | 9345.1096641526@sss.pgh.pa.us обсуждение исходный текст |
Ответ на | inconsistent/weird index usage (Dustin Sallings <dustin@spy.net>) |
Ответы |
Re: inconsistent/weird index usage
|
Список | pgsql-performance |
Dustin Sallings <dustin@spy.net> 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
В списке pgsql-performance по дате отправления: