Re: [PERFORM] Index usage for sorted query
Hi, Pierre-Frédéric, On Sat, 20 Nov 2004 17:12:43 +0100 Pierre-Frédéric Caillaud <[EMAIL PROTECTED]> wrote: > > WHERE cd='ca' ORDER BY l_postcode; > > Write : > > > WHERE cd='ca' ORDER BY cd, l_postcode; > > You have a multicolumn index, so you should specify a multicolumn sort > exactly the same as your index, and the planner will get it. Thanks, that seems to help. Seems weird to order by a column that is all the same value, but well, why not :-) Thanks a lot, Markus -- markus schaber | dipl. informatiker logi-track ag | rennweg 14-16 | ch 8001 zürich phone +41-43-888 62 52 | fax +41-43-888 62 53 mailto:[EMAIL PROTECTED] | www.logi-track.com ---(end of broadcast)--- TIP 9: the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match
Re: [PERFORM] Index usage for sorted query
Markus Schaber <[EMAIL PROTECTED]> writes: > But as it fetches all the rows through the index, why doesn't it > recognize that, fetching this way, the rows are already sorted by > l_postcode? Tell it to "ORDER BY cd, l_postcode". > Is Postgresql 8 more intelligend in this case? No. regards, tom lane ---(end of broadcast)--- TIP 9: the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match
Re: [PERFORM] Index usage for sorted query
Instead of : WHERE cd='ca' ORDER BY l_postcode; Write : WHERE cd='ca' ORDER BY cd, l_postcode; You have a multicolumn index, so you should specify a multicolumn sort exactly the same as your index, and the planner will get it. ---(end of broadcast)--- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faqs/FAQ.html
[PERFORM] Index usage for sorted query
Hello, I have the following query plan: logigis=# explain SELECT geom, ref_in_id as ref, nref_in_id as nref, st_name as name, substr(l_postcode,1,2) as postfirst, func_class as level FROM schabi.streets WHERE cd='ca' ORDER BY l_postcode; QUERY PLAN --- Sort (cost=2950123.42..2952466.07 rows=937059 width=290) Sort Key: l_postcode -> Index Scan using streets_name_idx on streets (cost=0.00..2857177.57 rows=937059 width=290) Index Cond: ((cd)::text = 'ca'::text) And I have, beside others, the following index: »streets_name_idx« btree (cd, l_postcode) As the query plan shows, my postgresql 7.4 does fine on using the index for the WHERE clause. But as it fetches all the rows through the index, why doesn't it recognize that, fetching this way, the rows are already sorted by l_postcode? As I have a larger set of data, it nearly breaks down our developer machine every time we do this, as it always creates a temporary copy of the large amount of data to sort it (setting sort_mem higher makes it swap, setting it lower makes it thrashing disk directly). Is Postgresql 8 more intelligend in this case? Thanks for your hints, Markus -- markus schaber | dipl. informatiker logi-track ag | rennweg 14-16 | ch 8001 zürich phone +41-43-888 62 52 | fax +41-43-888 62 53 mailto:[EMAIL PROTECTED] | www.logi-track.com ---(end of broadcast)--- TIP 6: Have you searched our list archives? http://archives.postgresql.org