Re: [PERFORM] select count(distinct ...) is slower than select distinct in about 5x

2013-12-11 Thread jacket41142
2013/12/11 Jeff Janes > On Tuesday, December 10, 2013, jacket41142 wrote: > >> Thanks very much. >> >> I think another problem is that the cost estimation isn't good enough to >> reflex real cost. Since we can see, from "explain analyze ...", >> count(distinct ...) has smallest cost between the o

[PERFORM] select count(distinct ...) is slower than select distinct in about 5x

2013-12-10 Thread jacket41142
Hi I'm just trying about PostgreSQL, I create a database "test" with a table "t1": test=> \d t1 Table "public.t1" Column | Type | Modifiers -+-+- col_id | integer | not null

Re: [PERFORM] select count(distinct ...) is slower than select distinct in about 5x

2013-12-10 Thread Jeff Janes
On Tuesday, December 10, 2013, jacket41142 wrote: > Thanks very much. > > I think another problem is that the cost estimation isn't good enough to > reflex real cost. Since we can see, from "explain analyze ...", > count(distinct ...) has smallest cost between the others, but since it uses > sorts

Re: [PERFORM] select count(distinct ...) is slower than select distinct in about 5x

2013-12-10 Thread jacket41142
I have done another experiment for count(*) vs count(distinct ...), on same table schema but with 1000 rows now. And for this time, the postgres version is 9.3.2 (9.3.2-1.pgdg12.4+1). These two has same resulted query plan with same estimated cost, but count(*) is straightly fast. test=> expla

Re: [PERFORM] select count(distinct ...) is slower than select distinct in about 5x

2013-12-10 Thread jacket41142
Thanks very much. I think another problem is that the cost estimation isn't good enough to reflex real cost. Since we can see, from "explain analyze ...", count(distinct ...) has smallest cost between the others, but since it uses sorts, the time complexity should be higher especially for large am

Re: [PERFORM] select count(distinct ...) is slower than select distinct in about 5x

2013-12-10 Thread Jeff Janes
On Tue, Dec 10, 2013 at 9:28 AM, jacket41142 wrote: > > test=> select distinct col_int from t1 group by col_int; > Time: 1177.936 ms > > So the performance difference is not very large. > But when I do that: > > test=> select count(distinct col_int) from t1; > count > --- > 1025 > (1 row)

Re: [PERFORM] select count(distinct ...) is slower than select distinct in about 5x

2013-12-10 Thread Kevin Grittner
jacket41142 wrote: > [ subject issue in detail ] Please review this thread: http://www.postgresql.org/message-id/flat/CAPNY-2Utce-c+kNTwsMCbAk58=9myeaevitxt9lo7r1k77j...@mail.gmail.com#CAPNY-2Utce-c+kNTwsMCbAk58=9myeaevitxt9lo7r1k77j...@mail.gmail.com -- Kevin Grittner EDB: http://www.enterpri

[PERFORM] select count(distinct ...) is slower than select distinct in about 5x

2013-12-10 Thread jacket41142
Hi I'm just trying about PostgreSQL, I create a database "test" with a table "t1": test=> \d t1 Table "public.t1" Column | Type | Modifiers -+-+- col_id | integer | not null