X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 5B47BD1B502 for ; Wed, 1 Oct 2003 11:48:34 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 12299-10 for ; Wed, 1 Oct 2003 08:47:47 -0300 (ADT) Received: from mail.messagingengine.com (out1.smtp.messagingengine.com [66.111.4.25]) by svr1.postgresql.org (Postfix) with ESMTP id 649D6D1B537 for ; Wed, 1 Oct 2003 08:47:44 -0300 (ADT) Received: from smtp.us2.messagingengine.com (localhost [127.0.0.1]) by localhost.localdomain (Postfix) with ESMTP id 11B6D24E7CC for ; Wed, 1 Oct 2003 07:47:47 -0400 (EDT) Received: from 10.202.2.133 ([10.202.2.133] helo=smtp.us2.messagingengine.com) by messagingengine.com with SMTP; Wed, 01 Oct 2003 07:47:47 -0400 Received: by smtp.us2.messagingengine.com (Postfix, from userid 99) id CAC7E74708; Wed, 1 Oct 2003 07:47:46 -0400 (EDT) Content-Disposition: inline Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="Big5" MIME-Version: 1.0 X-Mailer: MIME::Lite 1.2 (F2.71; T1.001; A1.51; B2.12; Q2.03) From: "CN" To: pgsql-sql@postgresql.org Date: Wed, 01 Oct 2003 03:47:46 -0800 X-Epoch: 1065008867 X-Sasl-enc: iHSNOH6anRqjdqYYrqmuGQ Subject: Creating Index Message-Id: <20031001114746.CAC7E74708@smtp.us2.messagingengine.com> X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.1 tagged_above=0.0 required=5.0 tests=BAYES_30, UPPERCASE_25_50 X-Spam-Level: X-Archive-Number: 200310/7 X-Sequence-Number: 15407 Hi! CREATE TABLE table1 ( d DATE PRIMARY KEY, amount INTEGER ); CREATE TABLE table2 ( PRIMARY KEY (y,m), y INTEGER, m INTEGER amount INTEGER ); CREATE VIEW view1 AS SELECT EXTRACT(YEAR FROM d) AS year, EXTRACT(MONTH FROM d) AS month, amount UNION ALL SELECT * from table2; Table1 contains 9000 rows and table2 contains 0 row. This query, which takes 13489 msec, is extremely slow as pgsql sequentially scans all rows in table1: EXPLAIN ANALYZE SELECT COUNT(*) FROM view1; I am in the impression that building an index on column d surely will help improve the performance but I am not smart enough to apply its usage explained in the manual. I would much appreciate if anyone could show me how to build that index something similar to (I guess) the following query (which is illegal of course): CREATE INDEX index1 ON table1 EXTRACT(YEAR FROM d) || EXTRACT(MONTH FROM d); TIA CN -- http://www.fastmail.fm - Faster than the air-speed velocity of an unladen european swallow