Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id CFB489F942C for ; Wed, 22 Aug 2007 09:58:00 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 06939-03 for ; Wed, 22 Aug 2007 09:57:51 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from rv-out-0910.google.com (rv-out-0910.google.com [209.85.198.187]) by postgresql.org (Postfix) with ESMTP id 06F8E9F946D for ; Wed, 22 Aug 2007 09:57:43 -0300 (ADT) Received: by rv-out-0910.google.com with SMTP id c24so111554rvf for ; Wed, 22 Aug 2007 05:57:42 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=kdcMMDEAZlZ8+Piqhpyw7NoP/minQCydCsYhiMs6ealraZLJ9jRP+rcLgPekplMeykPmj5s0dEHJRi2837dCCYCtdLb3Ow2AOsUyDKo3E5esO+/ZuzkzVuKBixxbBXx+K/T/fSa+Ut8TFtpXdQfxWgRZsY9qlFGxveGdpPIXcLU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=K6UNfQxYNBxFi8TPACcestMREtkbaGV48vIyjWg3aoDNH2ziMrALTfoz549Zvh2i0vkuqTOkOPRX6Gs62Gj8BB+A8dg2RGr74Nx9hHJ2Smr8/HDa2M/g03+YCuqvJ84e3TItWWTCFoU74yrfROFLMD5i6NphmsSLL8AORgoLr3U= Received: by 10.141.78.14 with SMTP id f14mr261222rvl.1187787462118; Wed, 22 Aug 2007 05:57:42 -0700 (PDT) Received: by 10.140.194.12 with HTTP; Wed, 22 Aug 2007 05:57:42 -0700 (PDT) Message-ID: Date: Wed, 22 Aug 2007 16:57:42 +0400 From: "Aleksandr Vinokurov" To: pgsql-sql@postgresql.org Subject: Partial index and query plan MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200708/194 X-Sequence-Number: 29132 Hello all, Imagine having this table: create table user_history ( rec_id SERIAL not null, date TIMESTAMP not null, action INT2 not null, uid INT4 not null, name CHAR(10) null default NULL, constraint PK_USER_HISTORY primary key (rec_id), constraint AK_DATE_USER_HIS unique (date) ); and this partial index: create unique index indx_date_action12_uid_user_his on user_history (date, uid) where action <> 0; and this query: select date from "user_history" where date > '2007-08-18 14:33' and date <= '2007-08-18 16:30' and uid = 1388 and action <> 0 limit 1; The question is why "explain analyze" shows a 'Filter: ("action" <> 0)' in plan: Limit (cost=0.00..3.05 rows=1 width=8) (actual time=4.798..4.798 rows=0 loops=1) -> Index Scan using indx_date_action12_uid_user_his on user_history (cost=0.00..6.10 rows=2 width=8) (actual time=4.791..4.791 rows=0 loops=1) Index Cond: ((date > '2007-08-18 14:33:40.60664'::timestamp without time zone) AND (date <= '2007-08-18 16:30:00'::timestamp without time zone) AND (uid = 138658)) Filter: ("action" <> 0) when this is a "where" case of the index?