Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 1AD259F9C27 for ; Wed, 22 Aug 2007 11:43:06 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 14361-05 for ; Wed, 22 Aug 2007 11:43:03 -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 BB67D9F9B96 for ; Wed, 22 Aug 2007 11:43:02 -0300 (ADT) Received: by rv-out-0910.google.com with SMTP id c24so130478rvf for ; Wed, 22 Aug 2007 07:43:00 -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:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=YTyJL8UKEt8jun/bFvOvAKxpnFxl+307cJBNcF/budp8COhOpggU8QW4qoHMc6Vp+FndiwJsmKj2tb8zqpWgtSrI7tL5hze0sO2w2fZZ/GEpETMQuyk7dSKseaYqq1gEA149q8fm2hWbzNtbJk3T6EohZ5KZJ3nvjbXd3vtHR0Q= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=b+gX8lhdvhJ9RCvCClngK+dRBmMsTvTLA7tlPQhdVXUG9foAH7djJduSY2M+j0R5bi8V8angBmxENct99oZeKiDxEekF9bwBykR2Ylr6d0GCY94P+pSAYJBeG0x+xonSdi4EXNPWPI6P0cbSgHZKwY3345WT8jJtVDDI7tuLTow= Received: by 10.141.142.15 with SMTP id u15mr315662rvn.1187793780766; Wed, 22 Aug 2007 07:43:00 -0700 (PDT) Received: by 10.141.98.12 with HTTP; Wed, 22 Aug 2007 07:43:00 -0700 (PDT) Message-ID: Date: Wed, 22 Aug 2007 09:43:00 -0500 From: "Scott Marlowe" To: "Aleksandr Vinokurov" Subject: Re: Partial index and query plan Cc: pgsql-sql@postgresql.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200708/198 X-Sequence-Number: 29136 On 8/22/07, Aleksandr Vinokurov wrote: > > 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) > ); > > 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) I don't see the issue here. The index being used is the same partial index you created. Maybe it's just a question of semantics?