Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1X0Qd0-0003R4-1z for pgsql-performance@arkaria.postgresql.org; Fri, 27 Jun 2014 07:31:22 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1X0Qcz-0001Pw-I2 for pgsql-performance@arkaria.postgresql.org; Fri, 27 Jun 2014 07:31:21 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1X0Qcx-0001Pf-3x for pgsql-performance@postgresql.org; Fri, 27 Jun 2014 07:31:20 +0000 Received: from m15-236.126.com ([220.181.15.236]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1X0Qcm-0005cW-5D for pgsql-performance@postgresql.org; Fri, 27 Jun 2014 07:31:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=Date:From:Message-ID:Subject:MIME-Version; bh=JD1Z5 OQIRN7XgTCxU6pd58qACUdokl7Zm5J8d1E9IK4=; b=axR9TzLLwoc75GQaOZcWZ xTglRCaHYKL0M4FsNd6OaHGMORVfdyMHIqTx00fZE/0EzdtX7v0ZMuHqahDJllQU 69waIefGLo9qpouI1cN+27JucR0WWg6OO2ZjgloQoEWzqGbn3oYziuZ8CCbpnKDq Yeu8PTFel/LkSZtU/iPsRs= Received: from songtebo$126.com ( [210.73.73.173] ) by ajax-webmail-sdy9 (Coremail) ; Fri, 27 Jun 2014 15:30:59 +0800 (GMT+08:00) Date: Fri, 27 Jun 2014 15:30:52 +0800 From: "songtebo" To: "pgsql-performance" Message-ID: <44934c03.2b413d.146dc3c04c6.Coremail.songtebo@126.com> Subject: Can improve 'limit 1' ? with slow function MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Mailer: NetEase Flash Mail 2.3.1.12 X-Priority: 3 (Normal) X-Originating-IP: [210.73.73.173] X-CM-TRANSID: 4sqowADnIQS0Ha1T6fC+AA--.6494W X-CM-SenderInfo: pvrqw3xherqiyswou0bp/1tbiJw63IU1r9XxW1wABsQ X-Coremail-Antispam: 1U5529EdanIXcx71UUUUU7vcSsGvfC2KfnxnUU== X-Pg-Spam-Score: -0.1 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org The simplified scene: select slowfunction() from a order by b limit 1 is slow than select slowfunction() from ( select * from a order by b limit 1) if there are many records in table 'a' The real scene: function ST_Distance_Sphere is slow than ST_Distance, the query: SELECT ST_Distance_Sphere(s, ST_GeomFromText('POINT(1 1)')) from road order by ST_Distance(s, ST_GeomFromText('POINT(1 1)')) limit 1 is slow than: select ST_Distance_Sphere(s, ST_GeomFromText('POINT(1 1)')) from (SELECT s from road order by ST_Distance(s, ST_GeomFromText('POINT(1 1)')) limit 1) as a There are about 7000 records in 'road'. -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance