pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tonio Caputo <tonioc@exeo.com.ar>
To: pgsql-jdbc@postgresql.org
Subject: Index scan with like expressions
Date: Tue, 17 Jul 2007 18:29:36 -0300
Message-ID: <1184707776.7307.65.camel@heracles.melo> (raw)

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











view thread (3+ messages)  latest in thread

Message-ID: <1184707776.7307.65.camel@heracles.melo>
Permalink:  ../1184707776.7307.65.camel@heracles.melo/
Also on:    postgresql.org/message-id/1184707776.7307.65.camel@heracles.melo

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: tonioc@exeo.com.ar
  Subject: Re: Index scan with like expressions
  In-Reply-To: <1184707776.7307.65.camel@heracles.melo>
  References: <1184707776.7307.65.camel@heracles.melo>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox