Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id 0BCC22E004A for ; Tue, 13 May 2008 15:02:34 -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 62505-10 for ; Tue, 13 May 2008 15:02:27 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from yw-out-2324.google.com (yw-out-2324.google.com [74.125.46.29]) by developer.postgresql.org (Postfix) with ESMTP id D38CD2E0045 for ; Tue, 13 May 2008 15:02:26 -0300 (ADT) Received: by yw-out-2324.google.com with SMTP id 3so1731768ywj.73 for ; Tue, 13 May 2008 11:02:21 -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=Ay6p4zMlRV8WvWvbmJW9EQmZ0YO2MDR5bDxsYUK9yrU=; b=dRi9PlQspgU81M0wqasbG6OtFyFtxnMC0ewXbmdldNQCpZydKKIgOlJuvwY0pmJkiOsvK4/HYsfuiBZmjc4MOtkIvimIINPwt/tN6a0E66VYhKp1HCjAxDz7vIW5e1gavESjYAYIARYOU5AC84Q9hkRbMxTvmWdYnix+IbqWTU4= 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=fwpHuWwFD1CXldUCAiZQFDFXRTr+2DUtGCP3xjbt8IOb9LAldBfQZPeGQy2m1QOmI0vFV1pYW6kx+HipQwfx/ub0wGckr4wYCFClmwiQ5/OZcweUV7HfLcqLOXvXbrZsFAA4KMBiZst3/DiMlwZ2H/JYo8BSsVa8/c+6fr6Ah38= Received: by 10.115.55.1 with SMTP id h1mr9493065wak.207.1210701740730; Tue, 13 May 2008 11:02:20 -0700 (PDT) Received: by 10.114.137.7 with HTTP; Tue, 13 May 2008 11:02:20 -0700 (PDT) Message-ID: Date: Tue, 13 May 2008 12:02:20 -0600 From: "Scott Marlowe" To: "idc danny" Subject: Re: Problem with 11 M records table Cc: pgsql-performance@postgresql.org In-Reply-To: <684043.20585.qm@web35307.mail.mud.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <684043.20585.qm@web35307.mail.mud.yahoo.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200805/172 X-Sequence-Number: 30140 On Tue, May 13, 2008 at 10:57 AM, idc danny wrote: > Hi everybody, > > I'm fairly new to PostgreSQL and I have a problem with > a query: > > SELECT * FROM "LockerEvents" LIMIT 10000 OFFSET > 10990000 > > The table LockerEvents has 11 Mlillions records on it > and this query takes about 60 seconds to complete. > Moreover, even after making for each column in the > table a index the EXPLAIN still uses sequential scan > instead of indexes. Yep. The way offset limit works is it first materializes the data needed for OFFSET+LIMIT rows, then throws away OFFSET worth's of data. So, it has to do a lot of retrieving. Better off to use something like: select * from table order by indexfield where indexfield between 10000000 and 10001000; which can use an index on indexfield, as long as the amount of data is small enough, etc...