Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 2708063332D for ; Tue, 22 Dec 2009 11:11:44 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 25244-09 for ; Tue, 22 Dec 2009 15:11:35 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from forward11.mail.yandex.net (forward11.mail.yandex.net [95.108.130.93]) by mail.postgresql.org (Postfix) with ESMTP id 842716324FF for ; Tue, 22 Dec 2009 11:11:36 -0400 (AST) Received: from webmail110.yandex.ru (webmail110.yandex.ru [95.108.130.10]) by forward11.mail.yandex.net (Yandex) with ESMTP id 13824F487F4 for ; Tue, 22 Dec 2009 18:11:22 +0300 (MSK) Received: from localhost (localhost.localdomain [127.0.0.1]) by webmail110.yandex.ru (Yandex) with ESMTP id E849D29BC1D8 for ; Tue, 22 Dec 2009 18:11:21 +0300 (MSK) X-Yandex-Spam: 1 X-Yandex-Front: webmail110 X-Yandex-TimeMark: 1261494681 Received: from user-28.81.118.217.in-addr.arpa (user-28.81.118.217.in-addr.arpa [217.118.81.28]) by mail.yandex.ru with HTTP; Tue, 22 Dec 2009 18:11:21 +0300 From: msi77 To: pgsql-sql@postgresql.org In-Reply-To: <20091222141231.GE10308@a-kretschmer.de> References: <20091222133527.3007bd96@dawn.webthatworks.it> <20091222141231.GE10308@a-kretschmer.de> Subject: Re: short-cutting if sum()>constant MIME-Version: 1.0 Message-Id: <6521261494681@webmail110.yandex.ru> Date: Tue, 22 Dec 2009 18:11:21 +0300 X-Mailer: Yamail [ http://yandex.ru ] 5.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=koi8-r X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=2.394 tagged_above=-10 required=5 tests=BAYES_40=-0.185, RCVD_IN_BL_SPAMCOP_NET=1.96, RCVD_IN_SORBS_WEB=0.619 X-Spam-Level: ** X-Archive-Number: 200912/60 X-Sequence-Number: 33498 Does PG support CTE? You can try it. > In response to Ivan Sergio Borgonovo : > > Развернуть > > Hi, > > > > I'd like to know if > > > > select sum(qty) from t where status=37; > > > > is > constant. > > > > qty is always >0. > > > > Is there a way to skip examining further rows and return a result > > ASAP? > I think no. > But you can create a new table with 2 columns: status (primary key) and > a column for the sum of qty. And you need a TRIGGER: update this table > for every insert, update and delete on your table t. > Now you can ask _this_ new table if the sum(qty) > your constant, this > should work very fast. > Just an idea... > Andreas > Яндекс.Почта. Письма есть. Спама - нет. http://mail.yandex.ru/nospam/sign