Re: [PERFORM] Slow query with backwards index scan

2007-07-30 Thread Tilmann Singer
* Nis Jørgensen <[EMAIL PROTECTED]> [20070730 18:33]: > It seems to me the subselect plan would benefit quite a bit from not > returning all rows, but only the 10 latest for each user. I believe the > problem is similar to what is discussed for UNIONs here: > > http://groups.google.dk/group/pgsql.

Re: [PERFORM] Slow query with backwards index scan

2007-07-28 Thread Tilmann Singer
* Craig James <[EMAIL PROTECTED]> [20070728 22:00]: > >>SELECT * FROM ( > >> (SELECT * FROM large_table lt > >> WHERE lt.user_id = 12345 > >> ORDER BY created_at DESC LIMIT 10) AS q1 > >> UNION > >> (SELECT * FROM large_table lt > >> WHERE user_id IN (SELECT contact_id FROM relationships WHERE > >

Re: [PERFORM] Slow query with backwards index scan

2007-07-28 Thread Tilmann Singer
* [EMAIL PROTECTED] <[EMAIL PROTECTED]> [20070728 21:05]: > Let's try putting the sort/limit in each piece of the UNION to speed them up > separately. > > SELECT * FROM ( > (SELECT * FROM large_table lt > WHERE lt.user_id = 12345 > ORDER BY created_at DESC LIMIT 10) AS q1 > UNION > (SELECT *

Re: [PERFORM] Slow query with backwards index scan

2007-07-28 Thread Tilmann Singer
* Nis Jørgensen <[EMAIL PROTECTED]> [20070727 20:31]: > How does the "obvious" UNION query do - ie: > > SELECT * FROM ( > SELECT * FROM large_table lt > WHERE lt.user_id = 12345 > > UNION > > SELECT * FROM large_table lt > WHERE user_id IN (SELECT contact_id FROM relationships WHERE user_id=1234

[PERFORM] Slow query with backwards index scan

2007-07-27 Thread Tilmann Singer
Dear list, I am having problems selecting the 10 most recent rows from a large table (4.5M rows), sorted by a date column of that table. The large table has a column user_id which either should match a given user_id, or should match the column contact_id in a correlated table where the user_id of