Received: from localhost (unknown [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id EA6602E00C2 for ; Thu, 29 Nov 2007 02:49:45 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 78377-05 for ; Thu, 29 Nov 2007 02:49:41 -0400 (AST) Received: from wa-out-1112.google.com (wa-out-1112.google.com [209.85.146.178]) by postgresql.org (Postfix) with ESMTP id B83E62E0084 for ; Thu, 29 Nov 2007 02:49:42 -0400 (AST) Received: by wa-out-1112.google.com with SMTP id m38so2322854waf for ; Wed, 28 Nov 2007 22:49:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; 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; bh=O9r/844JukmyTGJ4TcGD87xs9F1TkqjP5IC1LwPtnCg=; b=X7cnPrjc6CjNPvrmsXhr95Q4fgSN3B0v38PHjLvbVUHspmAE320AzQbbR2qzItDjxSuMh2JOR5GavRiFIvSyArzUmDe56C89e2GkflWKJK+/S+LdaHTl0k1bu4/iPtqrzRRVgKTEkd1zNTYACRcxYkFZl1Q7TwCS3JrQKSb8+Dw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=ZVPqm179n6keyBE/8rDQjWwUhomMuAce3aap7uSTWRLTwAnanXBkzq7+970ZiLPyFRZw5vuoreF9Xvz8jqV+76yYUyYpPZq1kd4riQARU6xrdAepHn9zT51Hxm6vj7+dQkdCz1CZ+qezc+VHSkvNyHA4v6BkaQ93UcNzdFIjAaU= Received: by 10.114.92.2 with SMTP id p2mr578752wab.1196318981640; Wed, 28 Nov 2007 22:49:41 -0800 (PST) Received: by 10.114.53.7 with HTTP; Wed, 28 Nov 2007 22:49:41 -0800 (PST) Message-ID: Date: Thu, 29 Nov 2007 00:49:41 -0600 From: "Scott Marlowe" To: cluster Subject: Re: Query only slow on first run Cc: "Steinar H. Gunderson" , pgsql-performance@postgresql.org In-Reply-To: <474DDA8F.3070801@amossen.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <056501c83128$55d58a90$8e00a8c0@tridecap.com> <20071127233833.GA24031@uio.no> <15029.1196209554@sss.pgh.pa.us> <474CBF98.6070508@amossen.dk> <20071128203442.GB30600@uio.no> <474DDA8F.3070801@amossen.dk> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200711/368 X-Sequence-Number: 27783 On Nov 28, 2007 3:15 PM, cluster wrote: > > The indexes don't contain visibility information, so Postgres has to look up > > the row on disk to verify it isn't dead. > > I guess this fact drastically decreases the performance. :-( > The number of rows with a random_number will just grow over time while > the number of questions with status = 1 will always be somewhat constant > at about 10.000 or most likely much less. Have you tried a partial index? create index xyz on tablename (random) where status = 1 > I could really use any kind of suggestion on how to improve the query in > order to make it scale better for large data sets The 6-7000 ms for a > clean run is really a showstopper. Need to get it below 70 ms somehow. Also, look into clustering the table on status or random every so often. More importantly, you might need to research a faster way to get your random results