Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 074659F9904 for ; Wed, 22 Aug 2007 01:20:31 -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 62870-07 for ; Wed, 22 Aug 2007 01:20:26 -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.189]) by postgresql.org (Postfix) with ESMTP id D18C69F97EE for ; Wed, 22 Aug 2007 01:20:26 -0300 (ADT) Received: by rv-out-0910.google.com with SMTP id c24so37226rvf for ; Tue, 21 Aug 2007 21:20:26 -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=ZzKt8cifb3ra1xjfyD+EI5G78nkwpADZD1L4/LOQ/SUvDqe/WLekjPGLA+TfA7xUoc5//HS68QUwNpVrgJnPboWKnVwXXWmrW+hUayh8+lFDklDAA+5CdelUYEuSdZmoVKjSJw0DVWJlPLToj8jG4YFC7mDIH1sfkdLPLc70oDY= 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=lHqUZchfNDrUnkpeaeS+z9I6xfspQbY/xSkGmg/Gd8CTW3ErxloLAVRlTZe4JPBZr2L6yAOjmpXSV/00STQGiZxPU5ByxeCkkH2A+d0DrDT4w4MqP/7T7W7UzGRhJfibi2QEv2yk/rvg0YZzx6Yxw5xgd9xEOLa0Ew9HB1n/hWU= Received: by 10.141.71.19 with SMTP id y19mr74993rvk.1187756425677; Tue, 21 Aug 2007 21:20:25 -0700 (PDT) Received: by 10.141.98.12 with HTTP; Tue, 21 Aug 2007 21:20:25 -0700 (PDT) Message-ID: Date: Tue, 21 Aug 2007 23:20:25 -0500 From: "Scott Marlowe" To: "Stephen Davies" Subject: Re: Optimising "in" queries Cc: pgsql-performance@postgresql.org In-Reply-To: <200708221210.36770.scldad@sdc.com.au> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <200708221210.36770.scldad@sdc.com.au> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200708/229 X-Sequence-Number: 26359 On 8/21/07, Stephen Davies wrote: > I have a PostgreSQL 8.2.4 table with some seven million rows. > > The psql query: > > select count(rdate),rdate from reading where sensor_id in > (1137,1138,1139) group by rdate order by rdate desc limit 1; > > takes a few seconds but: > > select count(rdate),rdate from reading where sensor_id in > (1137,1138,1139,1140) group by rdate order by rdate desc limit 1; > > (anything with four or more values in the "in" list) takes several > minutes. Can we see explain analyze output? (i.e. not just plain explain)