X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 5CA63D1B54C for ; Tue, 28 Oct 2003 18:58:14 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 44475-07 for ; Tue, 28 Oct 2003 14:57:43 -0400 (AST) Received: from omikron.sk (cepr.nustep.sk [81.0.222.49]) by svr1.postgresql.org (Postfix) with SMTP id 82478D1B545 for ; Tue, 28 Oct 2003 14:57:40 -0400 (AST) Received: (qmail 19324 invoked from network); 28 Oct 2003 18:57:24 -0000 Received: from nustep.casablanca.sk (HELO stratos) (81.0.208.19) by 0 with SMTP; 28 Oct 2003 18:57:24 -0000 Message-ID: <017201c39d85$533eed70$0200a8c0@stratos> From: "Cestmir Hybl" To: Subject: Ignoring index on (A is null), (A is not null) conditions Date: Tue, 28 Oct 2003 19:57:24 +0100 Organization: NUSTEP s.r.o. MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-2" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200310/712 X-Sequence-Number: 4460 Hi, suppose, for simplicity, there is a table with index like this: create table TABLE1 ( A integer ); create index TABLE1_A on TABLE1 (A); My question is: why psql (7.3.3) does not use index when filtering by A IS NULL, A IS NOT NULL expressions? In fact, I need to filter by expression ((A is null) or (A > const)). Is there a way to filter by this expression using index? Functional index cannot be used (except strange solution with CASE-ing and converting NULL values into some integer constant) ---------------------------------------------------------------------------- -- Index Scan using table1_a on table1 (cost=0.00..437.14 rows=29164 width=4) Index Cond: (a > 1000) ---------------------------------------------------------------------------- -- Seq Scan on table1 (cost=0.00..448.22 rows=1 width=4) Filter: (a IS NULL) -------------------------------------------------------- Seq Scan on table1 (cost=0.00..448.22 rows=30222 width=4) Filter: (a IS NOT NULL) ------------------------------------------------------------ Seq Scan on table1 (cost=0.00..523.77 rows=29164 width=4) Filter: ((a IS NULL) OR (a > 1000)) ------------------------------------------------------------ CH