Saturday, January 09. 2010Forcing the planner's hand with set enable_seqscan off WTFPrinter FriendlyRecommended Books: SQL Tuning SQL Cookbook
Trackbacks
Trackback specific URI for this entry
No Trackbacks
Comments
Display comments as
(Linear | Threaded)
We noticed a similar type of problem with 8.4.1 after moving from 8.3.5. Our 'fix' was to increase the default_statistics_target by a factor of 10 (it's set to 500 now, I think). Analyze is a bit slower now ...
Lance,
Great thought, but sadly doing that and reanalyzing the tables, did not seem to do the trick and slowed the analyze down considerably (and I ran out of memory) for the table I have that has large geometries in it. though I think you are right its the stats target that is off in some way. I ended up just increasing the seq_page_cost in the database to 2 ALTER DATABASE somedb SET seq_page_cost=2; And that seemed to fix my issue. I suspect that I have some other queries that are suffering from the same fate but not as noticeable as this one, so I'm going to retest them with this new setting and compare my old speeds with the new.
I hope you had an extra line after that query to re-enable seq_scan .. otherwise for the rest of the queries in the script it'd be off (which may or may not be what you want). :)
just use JOIN instead, and it will be fast.
SELECT i.item_name, i.geom FROM items i JOIN lufeature_types f ON i.feature_type = f.feature_type WHERE f.grouping IN('G','K') ; job done....
Greg,
We usually do. The reason We don't in this case, is that that is just one of many conditions used to filter data in this application, its easier to tack these on into the WHERE condition because some of these if joined would create duplicated data and I really don't need anything from these tables since they are just used as filters. Anryate the speed of these has always been just as fast if not faster than doing the JOIN approach because the filtered subqueries are standalone and return very few records. For example the above example really only returns 4 records in the IN.
You didn't post EXPLAIN ANALYZE plans so it's difficult to give useful advice.
You should probably post to -performance, including explain analyze results, to get to the bottom of the problem.
Jeff,
Thanks for the suggestion. Unfortunately I can't for this piece without divulging snippets of code under NDA agreements. I'll try to formulate a standalone example that exhibits the same behavior. It would probably be easier to follow with a simplified reproducible standalone example anyway. As Lance experienced too. Didn't run into this particular problem when running in 8.3 and the production one I recently upgraded to 8.4 from 8.3 (taking the 8.4 config and making the custom adjustments I had made to the 8.3). Also as mentioned -- which was weird -- the development one only started to exhibit the same bizarre behavior after I vacuum analyzed the tables where as I imagine the production undergoes much more vacuuming since data is constantly being added to it.
It sounds like it may be a planner or stats bug. If multiple people are having problems, it would be nice to find a case that's free of sensitive data, code and queries. I understand that's not always possible though.
|
Entry's LinksQuicksearchCalendar
Categories
Blog Administration |