[HACKERS] Why is sorting on two columns so slower than sorting on one column?

2010-12-23 Thread Jie Li
Hi, Here is the test table, postgres=# \d big_wf Table public.big_wf Column | Type | Modifiers +-+--- age| integer | id | integer | postgres=# \dt+ big_wf List of relations Schema | Name | Type | Owner | Size | Description

Re: [HACKERS] Why is sorting on two columns so slower than sorting on one column?

2010-12-23 Thread Kenneth Marshall
On Thu, Dec 23, 2010 at 02:33:12AM -0500, Jie Li wrote: Hi, Here is the test table, postgres=# \d big_wf Table public.big_wf Column | Type | Modifiers +-+--- age| integer | id | integer | postgres=# \dt+ big_wf List of

Re: [HACKERS] Why is sorting on two columns so slower than sorting on one column?

2010-12-23 Thread Marti Raudsepp
On Thu, Dec 23, 2010 at 09:33, Jie Li jay23j...@gmail.com wrote: While the first sorting takes about only 6 seconds, the second one takes over 30 seconds,  Is this too much than expected? Is there any possible optimization ? If you're doing these queries often, you should: CREATE INDEX

Re: [HACKERS] Why is sorting on two columns so slower than sorting on one column?

2010-12-23 Thread Li Jie
Hi Marti, Thanks for your help! I guess I understand what you mean, a clustered index will make sorting as cheap as a seq scan, right? But what I meant is, is there any potential optimization for the backend implementation? Intuitively, if sorting on one column or two columns will incur the