Received: from localhost (unknown [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id E15CC9FCD3A for ; Fri, 26 Oct 2007 18:10:51 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 03880-02-6 for ; Fri, 26 Oct 2007 18:10:46 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from linus.numail.org (mail.numail.org [216.130.152.7]) by postgresql.org (Postfix) with ESMTP id 9125D9FCB3F for ; Fri, 26 Oct 2007 18:10:20 -0300 (ADT) Received: (qmail 13762 invoked by uid 0); 26 Oct 2007 21:10:19 -0000 Received: from 72.15.64.64 by linus.numail.org (envelope-from , uid 101) with qmail-scanner-1.23 (fsecure: 4.50/2111/fprot(2004-10-21)/avp(2004-10-21). Clear:RC:1(72.15.64.64):. Processed in 0.126409 secs); 26 Oct 2007 21:10:19 -0000 Received: from unknown (HELO ?24.25.1.100?) (72.15.64.64) by mail.numail.org with AES256-SHA encrypted SMTP; 26 Oct 2007 21:10:19 -0000 Message-ID: <472257B7.5090702@laotraesquina.com.ar> Date: Fri, 26 Oct 2007 17:10:15 -0400 From: Pablo Alcaraz User-Agent: Thunderbird 2.0.0.6 (Windows/20070728) MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: Speed difference between select ... union select ... and select from partitioned_table References: <47225014.5040101@laotraesquina.com.ar> In-Reply-To: <47225014.5040101@laotraesquina.com.ar> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.472 tagged_above=0 required=5 tests=BAYES_50=0.001, SARE_MILLIONSOF=0.315, SUBJECT_FUZZY_TION=0.156 X-Spam-Level: X-Archive-Number: 200710/310 X-Sequence-Number: 27332 I forgot to post the times: query-union: 21:59 query-heritage: 1:31:24 Regards Pablo Pablo Alcaraz wrote: > Hi List! > > I executed 2 equivalents queries. The first one uses a union > structure. The second uses a partitioned table. The tables are the > same with 30 millions of rows each one and the returned rows are the > same. > > But the union query perform faster than the partitioned query. > > My question is: why? :) > > [pabloa@igor testeo]$ cat query-union.sql > select e, p, sum( c) as c > from ( > select e, p, count( *) as c > from tt_00003 > group by e, p > union > select e, p, count( *) as c > from tt_00006 > group by e, p > union > select e, p, count( *) as c > from tt_00009 > group by e, p > union > select e, p, count( *) as c > from tt_00012 > group by e, p > union > select e, p, count( *) as c > from tt_00015 > group by e, p > ) as t > group by e, p > order by e, p desc; > > > > [pabloa@igor testeo]$ cat query-heritage.sql > select e, p, count( *) as c > from tt > group by e, p > order by e, p desc; > > > The server is a Athlon 64x2 6000+ 2 Gb RAM PostreSQL 8.2.5 > > The structure tables are: > > CREATE TABLE tt_00003 > ( > -- Inherited: idtt bigint NOT NULL, > -- Inherited: idttp bigint NOT NULL, > -- Inherited: e integer NOT NULL, > -- Inherited: dmodi timestamp without time zone NOT NULL DEFAULT now(), > -- Inherited: p integer NOT NULL DEFAULT 0, > -- Inherited: m text NOT NULL, > CONSTRAINT tt_00003_pkey PRIMARY KEY (idtt), > CONSTRAINT tt_00003_idtt_check CHECK (idtt >= 1::bigint AND idtt <= > 30000000::bigint) > ) INHERITS (tt) > WITHOUT OIDS; > ALTER TABLE tt_00003 ; > > CREATE INDEX tt_00003_e > ON tt_00003 > USING btree > (e); > > > > > > > ---------------------------(end of broadcast)--------------------------- > TIP 7: You can help support the PostgreSQL project by donating at > > http://www.postgresql.org/about/donate >