Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 5E7509FBDF2 for ; Tue, 17 Jul 2007 18:30:50 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 41039-05 for ; Tue, 17 Jul 2007 18:30:41 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from fe0.millic.com.ar (mx060.millic.com.ar [200.81.249.60]) by postgresql.org (Postfix) with ESMTP id 528999FBDEF for ; Tue, 17 Jul 2007 18:30:43 -0300 (ADT) Received: from 200-122-19-40.dsl.prima.net.ar ([200.122.19.40]:41942 "EHLO localhost.localdomain" smtp-auth: "tonioc@exeo.com.ar") by mr0.millic.com.ar with ESMTP id S376881AbXGQVai (ORCPT ); Tue, 17 Jul 2007 18:30:38 -0300 X-Comment: RFC 2476 MSA function at fe0.millic.com.ar logged sender identity as: tonioc@exeo.com.ar Received: from [192.168.1.51] (helo=[192.168.1.51]) by localhost.localdomain with esmtp (Exim 4.50) id 1IAucn-000590-18 for pgsql-jdbc@postgresql.org; Tue, 17 Jul 2007 18:30:29 -0300 Subject: Index scan with like expressions From: Tonio Caputo To: pgsql-jdbc@postgresql.org Content-Type: text/plain Date: Tue, 17 Jul 2007 18:29:36 -0300 Message-Id: <1184707776.7307.65.camel@heracles.melo> Mime-Version: 1.0 X-Mailer: Evolution 2.10.1 Content-Transfer-Encoding: 7bit X-Millicom-Alerce-Info: Al X-Millicom-Alerce-MRId: d279cb9c0f6e0d7742021f6db1ac14ed X-Millicom-Alerce-SpamAnalisis: spam X-Millicom-Alerce-From: tonioc@exeo.com.ar X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.5 tagged_above=0 required=5 tests=AWL=0.499, BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 200707/78 X-Sequence-Number: 17252 Hi everybody, I'm having some trouble with index scan using like expressions, using JDBC, but not in psql where the index is used. Configuration and tables: Postgres 8.1.4 My table "inscriptions": Column | Type | Modifiers ------------------------+---------+----------------------------------------------------------- id | integer | not null default code | text | not null beings_id | integer | not null inscription_types_t_id | integer | not null emitters_t_id | integer | not null date_from | date | date_to | date | localizations_id | integer | Indexes: "inscriptions_pkey" PRIMARY KEY, btree (id) "inscriptions_code_ikey" btree (code text_pattern_ops) My query: select beings_id from inscriptions where code like '999999'; If I make an explain in psql: QUERY PLAN ------------------------------------------------------------------------------------------- Index Scan using inscriptions_code_ikey on inscriptions (cost=0.00..6.01 rows=1 width=4) Index Cond: (code ~=~ '99999'::text) Filter: (code ~~ '99999'::text) If I do it from my java application with a parameter : select beings_id from inscriptions where code like ?; 2007-07-17 18:15:46,426 INFO [isoa.entities.bean.EntitiesApiBean] EXPLAIN: Seq Scan on inscriptions (cost=100000000.00..100606290.60 rows=141577 width=4) 2007-07-17 18:15:46,426 INFO [isoa.entities.bean.EntitiesApiBean] EXPLAIN: Filter: (code ~~ ($1)::text) If I do it from my java application explicitly writing my code value in the sql-string I get the correct plan. I think I'm missing some important issue here, anyone can give me a little help. Thanks in advance tonioc