Re: [SQL] SELECT DISTINCT too slow

2006-06-01 Thread Florian Weimer
* Alvaro Herrera: > Miroslav ?ulc wrote: >> The GROUP BY is really fast :-) > > Doh! How does it do it? It uses a hash table and can therefore discard duplicate rows more quickly (essentially linear time in the number of rows if the number of different rows is bounded).

Re: [SQL] SELECT DISTINCT too slow

2006-06-01 Thread Miroslav Šulc
Greg Stark napsal(a): Actually you could try the equivalent query: SELECT Key FROM MRTPContactValue GROUP BY Key This may or may not be faster because it can use a hash aggregate plan. I would expect it to be faster here because there are few distinct keys and the planner predicts that.

Re: [SQL] SELECT DISTINCT too slow

2006-06-01 Thread Greg Stark
Alvaro Herrera <[EMAIL PROTECTED]> writes: > Miroslav ?ulc wrote: > > Well, "key" is not primary key from another table. It is just a column > > in pair "key" => "value". > > The structure of the table is this: > > > > Id (primary key) > > MRTPContactId (id of contact from table MRTPContact) > >

Re: [SQL] SELECT DISTINCT too slow

2006-06-01 Thread Alvaro Herrera
Miroslav ?ulc wrote: > The GROUP BY is really fast :-) Doh! How does it do it? -- Alvaro Herrerahttp://www.CommandPrompt.com/ The PostgreSQL Company - Command Prompt, Inc. ---(end of broadcast)--- TIP 1: if posting

Re: [SQL] SELECT DISTINCT too slow

2006-06-01 Thread Miroslav Šulc
The GROUP BY is really fast :-) Thank you. Miroslav Šulc Tom Lane napsal(a): > Try > SELECT Key FROM MRTPContactValue GROUP BY Key > > The "select distinct" code is a bit old and crufty, GROUP BY is usually > smarter. > > regards, tom lane > begin:vcard fn;quoted-

Re: [SQL] SELECT DISTINCT too slow

2006-06-01 Thread Tom Lane
=?ISO-8859-2?Q?Miroslav_=A9ulc?= <[EMAIL PROTECTED]> writes: > I have a table with cca 400,000 rows. The table contains column "key" of > varchar(20) type containing 10 distinct values. I want to get out what > distinct values are present in the column. I use this simple query, > which is very slow

Re: [SQL] SELECT DISTINCT too slow

2006-06-01 Thread Miroslav Šulc
It might be a good solution :-) Thank you for your help. Miroslav Šulc Alvaro Herrera napsal(a): > Miroslav ?ulc wrote: > >> Well, "key" is not primary key from another table. It is just a column >> in pair "key" => "value". >> The structure of the table is this: >> >> Id (primary key) >> MR

Re: [SQL] SELECT DISTINCT too slow

2006-06-01 Thread Alvaro Herrera
Miroslav ?ulc wrote: > Well, "key" is not primary key from another table. It is just a column > in pair "key" => "value". > The structure of the table is this: > > Id (primary key) > MRTPContactId (id of contact from table MRTPContact) > Key (key from pair key => value) > Value (value from pair ke

Re: [SQL] SELECT DISTINCT too slow

2006-06-01 Thread Miroslav Šulc
Well, "key" is not primary key from another table. It is just a column in pair "key" => "value". The structure of the table is this: Id (primary key) MRTPContactId (id of contact from table MRTPContact) Key (key from pair key => value) Value (value from pair key => value) So I want the get th

Re: [SQL] SELECT DISTINCT too slow

2006-06-01 Thread Alvaro Herrera
Miroslav ?ulc wrote: > Hello, > > I have a table with cca 400,000 rows. The table contains column "key" of > varchar(20) type containing 10 distinct values. I want to get out what > distinct values are present in the column. I use this simple query, > which is very slow: > > SELECT DISTINCT Key F

[SQL] SELECT DISTINCT too slow

2006-06-01 Thread Miroslav Šulc
Hello, I have a table with cca 400,000 rows. The table contains column "key" of varchar(20) type containing 10 distinct values. I want to get out what distinct values are present in the column. I use this simple query, which is very slow: SELECT DISTINCT Key FROM MRTPContactValue Here is the