Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 1F3D86336B2 for ; Tue, 17 Aug 2010 04:26:30 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 97915-07 for ; Tue, 17 Aug 2010 07:26:22 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from gmmr6.centrum.cz (gmmr6.centrum.cz [90.183.38.131]) by mail.postgresql.org (Postfix) with ESMTP id EF4896336A7 for ; Tue, 17 Aug 2010 04:26:22 -0300 (ADT) Received: from gmma3 (unknown [90.183.38.133]) by gmmr6.centrum.cz (Postfix) with ESMTP id E6B014233EC8 for ; Tue, 17 Aug 2010 09:26:19 +0200 (CEST) Received: from gmmr5.centrum.cz ([127.0.0.1]) by gmma3 (gigamail-antispam); Tue, 17 Aug 2010 09:26:20 +0200 Received: from gmmr5.centrum.cz (lb2-self.cent [10.20.11.7]) by gmma3 (esets_smtp); Tue, 17 Aug 2010 09:26:20 +0200 Received: from mail1002.cent (unknown [90.183.38.132]) by gmmr5.centrum.cz (Postfix) with SMTP id D73BC80004B3 for ; Tue, 17 Aug 2010 09:26:19 +0200 (CEST) Received: from localhost by localhost (Centrum Email Forwarder); Tue, 17 Aug 2010 09:26:19 +0200 To: Subject: Search query is curious Received: from 80.250.18.198 (X-Forwarded-For: 80.250.18.198) by mail1002.centrum.cz (centrum.cz multimail) with HTTP Date: Tue, 17 Aug 2010 09:26:19 +0200 From: X-Mailer: Centrum Email 5.3 X-Priority: 3 MIME-Version: 1.0 X-Maser: brud Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <1282029979.831570.27725.nullmailer@mail1002.cent> X-EsetResult: clean X-CentrumSpamScore: +66 X-SpamDetected: 0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.01 tagged_above=-10 required=5 tests=BAYES_20=-0.001, T_RP_MATCHES_RCVD=-0.01, UNPARSEABLE_RELAY=0.001 X-Spam-Level: X-Archive-Number: 201008/173 X-Sequence-Number: 40016 Hi, I've database of lyrics and I'm using this query for suggest box. SELECT views, title, id FROM songs WHERE title ILIKE 'bey%' ORDER BY views DESC LIMIT 15; In query plan is this line: -> Seq Scan on songs (cost=0.00..11473.56 rows=5055 width=23) (actual time=1.088..89.863 rows=77 loops=1) it takes about 90ms but when i modify query (remove sort) SELECT views, title, id FROM songs WHERE title ILIKE 'bey%' LIMIT 15; In query plan -> Seq Scan on songs (cost=0.00..11473.56 rows=5055 width=23) (actual time=1.020..20.601 rows=15 loops=1 seq scan takes only 20ms now, why? Or any suggestion to optimize this query? In table songs are about 150.000 rows. Thank you for your reply. Best regards. Marek Fiala