Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id E77742E0096 for ; Mon, 26 May 2008 20:32:56 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 25382-03 for ; Mon, 26 May 2008 20:32:48 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from wa-out-1112.google.com (wa-out-1112.google.com [209.85.146.177]) by developer.postgresql.org (Postfix) with ESMTP id BB0962E0079 for ; Mon, 26 May 2008 20:32:52 -0300 (ADT) Received: by wa-out-1112.google.com with SMTP id n4so2357676wag.5 for ; Mon, 26 May 2008 16:32:51 -0700 (PDT) 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=lKj1icbHmgy7NxOMnEvzNdTzVvq+ZjhiqLw6yfUEjwk=; b=jFJmK2QTH2HpOaqoBxryDvpCnIJpKq9pUAQUZJnK2TNntWuDKLz8hNWW1gBGDsponMKDUunbBHfP+3PQXtpFMTPxWtn/DxoiLXZAjL/CihbyofIHBnF45N2oifNcmAFfH5y2xjHnGF0f6BQTMJdENnWx0jIC34Sae9zAqLAVQAs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=W2CKvimuAiEZy66OIfgP84GK6NkoPiGxqSMXgpwqJC+Hs5XU5Xp0StqvWDRm6lu+SRjRZi+Bqp6GDipD47aJg3VuoV6u78IrumRYLokY1iCt5BFcsxLHo8h2XwTztdVmBvUClFfYIWL7mbYAolfxKqC9NPSvpIpFKuh7ga9Fj0c= Received: by 10.114.37.1 with SMTP id k1mr609428wak.143.1211844770895; Mon, 26 May 2008 16:32:50 -0700 (PDT) Received: by 10.114.56.5 with HTTP; Mon, 26 May 2008 16:32:50 -0700 (PDT) Message-ID: <82fa9e310805261632y46f306fdh84e2da62ffbd7873@mail.gmail.com> Date: Mon, 26 May 2008 16:32:50 -0700 From: mark To: Justin Subject: Re: select query takes 13 seconds to run with index Cc: pgsql-general@postgresql.org, pgsql-performance@postgresql.org In-Reply-To: <483B4729.7050402@emproshunts.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <82fa9e310805261549m2362fbe8sbf18789938fee833@mail.gmail.com> <483B4729.7050402@emproshunts.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200805/953 X-Sequence-Number: 133352 On Mon, May 26, 2008 at 4:26 PM, Justin wrote: > mark wrote: >> Hi, is there anyway this can be made faster? id is the primary key, >> and there is an index on uid.. >> thanks >> EXPLAIN ANALYZE select * from pokes where uid = 578439028 order by id >> DESC limit 6; >> QUERY >> PLAN >> >> ---------------------------------------------------------------------------------------------------------------------------------------------------- >> Limit (cost=0.00..9329.02 rows=6 width=135) (actual >> time=13612.247..13612.247 rows=0 loops=1) >> -> Index Scan Backward using pokes_pkey on pokes >> (cost=0.00..5182270.69 rows=3333 width=135) (actual >> time=13612.245..13612.245 rows=0 loops=1) >> Filter: (uid = 578439028) >> Total runtime: 13612.369 ms >> (4 rows) > First this should be posted on performance list. sorry about this. > how many records are in this table? 22334262, 22 million records. > The estimate is way off, when was the last time Vaccum was on the table? about a week ago i ran this VACUUM VERBOSE ANALYZE; this table is never updated or deleted, rows are just inserted... > What verison of Postgresql are you running 8.3.1 > Size of the Table 22 million rows approximately > Table layout CREATE TABLE pokes ( id serial NOT NULL, uid integer, action_id integer, created timestamp without time zone DEFAULT now(), friend_id integer, message text, pic text, "name" text, CONSTRAINT pokes_pkey PRIMARY KEY (id) ) WITH (OIDS=FALSE); ALTER TABLE pokes OWNER TO postgres; -- Index: idx_action_idx -- DROP INDEX idx_action_idx; CREATE INDEX idx_action_idx ON pokes USING btree (action_id); -- Index: idx_friend_id -- DROP INDEX idx_friend_id; CREATE INDEX idx_friend_id ON pokes USING btree (friend_id); -- Index: idx_pokes_uid -- DROP INDEX idx_pokes_uid; CREATE INDEX idx_pokes_uid ON pokes USING btree (uid); > Load on the database how do i measure load on database?