Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 8AF5C6323C1 for ; Wed, 18 Nov 2009 15:39:46 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 64051-09 for ; Wed, 18 Nov 2009 19:39:32 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-yw0-f198.google.com (mail-yw0-f198.google.com [209.85.211.198]) by mail.postgresql.org (Postfix) with ESMTP id B01D66321CB for ; Wed, 18 Nov 2009 15:39:35 -0400 (AST) Received: by ywh36 with SMTP id 36so1359778ywh.15 for ; Wed, 18 Nov 2009 11:39:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type; bh=mFqMoBk8mcbeBM18ONEvqPakq8ABQD9Pfv55ZWRaUz4=; b=U9aHiVm4vkvBUZJCkqRcSLfmoczC/KKpi7Yti7jrf11TWFzOECNYlwNMyVKSLCdLWg D+dF55Z7Gb1Z3OPMRuvolMprRKuY6EfAW8j1aIo9ZpIMHqFNCUL59hoDaBrRl0OUbhx8 wcMxdthH1KZIB4xta1KWCuga+YWgGozuqg6oo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=ihNNr/F45n3k+dnVq7UgOn2Jw90+B7WRcuPPwe185AChaWbp37baaiLaqXhWk33cyA EvoxCcKZNl6wfHq3VCSIc9LBzO2r7F5pkbAwJFs+KtTfYnjnNnVWO+0hZ83mlpLquUel pGQNjSm3yHnNUaiWa0Kfh52e0hhmVmOsgoxeQ= MIME-Version: 1.0 Received: by 10.150.113.3 with SMTP id l3mr3046693ybc.90.1258573174444; Wed, 18 Nov 2009 11:39:34 -0800 (PST) In-Reply-To: <5ab13580911181133k6204bbb0h33a695e618bfa02b@mail.gmail.com> References: <5ab13580911181121g6e89759doa6c6ea6557424f71@mail.gmail.com> <200911182027.08857.guillaume@lelarge.info> <162867790911181130n74be837eo29e3c408724c88f7@mail.gmail.com> <5ab13580911181133k6204bbb0h33a695e618bfa02b@mail.gmail.com> Date: Wed, 18 Nov 2009 20:39:34 +0100 Message-ID: <162867790911181139s38dd9ae4n7b1474523d3f2c3b@mail.gmail.com> Subject: Re: LIMIT BASED ON PERCENT From: Pavel Stehule To: Lee Hachadoorian Cc: pgsql-sql@postgresql.org Content-Type: text/plain; charset=UTF-8 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.575 tagged_above=-10 required=5 tests=AWL=0.024, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200911/57 X-Sequence-Number: 33408 2009/11/18 Lee Hachadoorian : > On Wed, Nov 18, 2009 at 2:30 PM, Pavel Stehule wrote: >> yes, and don't use 20%. >> >> select * from foo order by somecol limit (select (count(*)*0.2)::int from foo) >> >> Regards >> Pavel > > Is this faster on a large table? Because (select (count(*)*20/100)) worked fine. > this is +/- same - 20/100 is maybe about 0.000001% faster - you don't need one float to query cast, but this operation is only one pqr query. The problem is two full scan of table. Pavel