Received: from localhost (unknown [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id C91769FCCCA for ; Fri, 26 Oct 2007 17:44:28 -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 86785-06 for ; Fri, 26 Oct 2007 17:44:25 -0300 (ADT) X-Greylist: delayed 00:06:39.488337 by SQLgrey-1.7.5 Received: from linus.numail.org (mail.numail.org [216.130.152.7]) by postgresql.org (Postfix) with ESMTP id 603019FCCA6 for ; Fri, 26 Oct 2007 17:44:25 -0300 (ADT) Received: (qmail 24623 invoked by uid 0); 26 Oct 2007 20:37:44 -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.080704 secs); 26 Oct 2007 20:37:44 -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 20:37:43 -0000 Message-ID: <47225014.5040101@laotraesquina.com.ar> Date: Fri, 26 Oct 2007 16:37:40 -0400 From: Pablo Alcaraz User-Agent: Thunderbird 2.0.0.6 (Windows/20070728) MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Speed difference between select ... union select ... and select from partitioned_table 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/307 X-Sequence-Number: 27329 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);