X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 6C1F4329E45 for ; Fri, 24 Sep 2004 12:18:38 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 15592-08 for ; Fri, 24 Sep 2004 11:18:33 +0000 (GMT) Received: from pt.dn.ua (pt.finfort.com [193.110.72.114]) by svr1.postgresql.org (Postfix) with ESMTP id 33686329E3C for ; Fri, 24 Sep 2004 12:18:32 +0100 (BST) Received: from vst.donetsk.ua ([192.168.101.13]) by pt.dn.ua (8.12.11/8.12.8) with ESMTP id i8OBISHg001285 for ; Fri, 24 Sep 2004 14:18:29 +0300 (EEST) (envelope-from vst@vst.donetsk.ua) Message-ID: <41542D7C.6070402@vst.donetsk.ua> Date: Fri, 24 Sep 2004 14:21:48 +0000 From: "Vladimir S. Tikhonjuk" User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.6) Gecko/20040324 X-Accept-Language: ru MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: INDEX problem Content-Type: text/plain; charset=KOI8-R; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=2.8 tagged_above=0.0 required=5.0 tests=DATE_IN_FUTURE_03_06 X-Spam-Level: ** X-Archive-Number: 200409/214 X-Sequence-Number: 19060 Hi all! I have such table: CREATE TABLE object ( id SERIAL, object_type_id int8 ); This table has 4 000 000 rows. There are 2 index: CREATE INDEX object_id_idx ON object(id); CREATE INDEX object_object_type_id_idx ON object(object_type_id); So: # EXPLAIN SELECT * FROM object WHERE id = 1::int8; Index Scan using object_id_idx on object (cost=0.00..92323.66 rows=23650 width=29) Index Cond: (id = 1::bigint) Here everything is O.K. # EXPLAIN SELECT * FROM object WHERE object_type_id = 1::int8; Index Scan using object_object_type_id_idx on object (cost=0.00..92323.66 rows=23650 width=29) Index Cond: (object_type_id = 1::bigint) Here everything is O.K. too... but! # EXPLAIN SELECT * FROM object WHERE object_type_id IN (1::int8, 21::int8); Seq Scan on object (cost=0.00..105730.00 rows=47182 width=29) Filter: ((object_type_id = 1::bigint) OR (object_type_id = 21::bigint)) The same results after: # EXPLAIN SELECT * FROM object WHERE object_type_id = 1::int8 OR object_type_id = 21::int8; Why Postgres didn't use index here ??? # EXPLAIN ANALYZE SELECT * FROM object WHERE object_type_id IN (1::int8, 21::int8); Seq Scan on object (cost=0.00..105730.00 rows=47182 width=29) (actual time=20744.910..20744.910 rows=0 loops=1) Filter: ((object_type_id = 1::bigint) OR (object_type_id = 21::bigint)) Total runtime: 20745.022 ms Best regards, Vladimir S. Tikhonjuk