Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dYBAw-0005YR-Ob for pgsql-bugs@arkaria.postgresql.org; Thu, 20 Jul 2017 13:07:30 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dYBAw-0005M8-6l for pgsql-bugs@arkaria.postgresql.org; Thu, 20 Jul 2017 13:07:30 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dY64t-0006DS-Ga for pgsql-bugs@postgresql.org; Thu, 20 Jul 2017 07:40:55 +0000 Received: from forward1h.cmail.yandex.net ([87.250.230.16]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dY64k-000569-5b for pgsql-bugs@postgresql.org; Thu, 20 Jul 2017 07:40:54 +0000 Received: from mxback19j.mail.yandex.net (mxback19j.mail.yandex.net [IPv6:2a02:6b8:0:1619::95]) by forward1h.cmail.yandex.net (Yandex) with ESMTP id 0065E20F4F; Thu, 20 Jul 2017 10:40:41 +0300 (MSK) Received: from web1m.yandex.ru (web1m.yandex.ru [37.140.138.92]) by mxback19j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id Eraswarnq0-eeneo0Tj; Thu, 20 Jul 2017 10:40:40 +0300 Received: by web1m.yandex.ru with HTTP; Thu, 20 Jul 2017 10:40:40 +0300 From: buhhunyx@tut.by To: Tom Lane Cc: pgsql-bugs@postgresql.org In-Reply-To: <7335.1500474080@sss.pgh.pa.us> References: <20170719114246.19352.23577@wrigleys.postgresql.org> <7335.1500474080@sss.pgh.pa.us> Subject: Re: BUG #14750: Seq Scan instead of Index Scan works without limitation MIME-Version: 1.0 Message-Id: <714641500536440@web1m.yandex.ru> X-Mailer: Yamail [ http://yandex.ru ] 5.0 Date: Thu, 20 Jul 2017 10:40:40 +0300 Content-Transfer-Encoding: 7bit Content-Type: text/plain List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Seq Scan is fine except its ignore PRIMARY KEY and UNIQUE CONSTRAINT: in case result is found it should be immediatly returned to avoid scan rest of data: # explain analyze select accountid from accounts where accountname = 'accountId50'; Seq Scan on accounts (cost=0.00..2.50 rows=1 width=12) (actual time=0.018..0.029 rows=1 loops=1) Filter: ((accountname)::text = 'accountId50'::text) Rows Removed by Filter: 119 Planning time: 0.075 ms Execution time: 0.048 ms In product no 'LIMIT 1' specified because first found result expected; in case of huge amout simple queries difference is valuable: # explain analyze select accountid from accounts where accountname = 'accountId50' limit 1; Limit (cost=0.00..2.50 rows=1 width=12) (actual time=0.016..0.016 rows=1 loops=1) -> Seq Scan on accounts (cost=0.00..2.50 rows=1 width=12) (actual time=0.014..0.014 rows=1 loops=1) Filter: ((accountname)::text = 'accountId50'::text) Rows Removed by Filter: 50 Planning time: 0.084 ms Execution time: 0.035 ms -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs