Tom Lane wrote:
> 
> Tomasz Myrta <[EMAIL PROTECTED]> writes:
> > Why the first expression is 25 times slower?
> 
> Hard to say, when you haven't shown us the schema.  (Column datatypes,
> definitions of available indexes, etc are all critical information for
> this sort of question.)
OK 
Don't panic with names, They are polish ;-)

1. TABLES
create table TRASY(
  id_trasy              integer  not null PRIMARY KEY,
  del                   date     default '9999-12-31',
  nazwa                 varchar  (80)
);

create table KURSY(
  id_kursu              integer  not null PRIMARY KEY,
  id_trasy              integer  not null references TRASY,
  data_kursu            date     not null,
  limit_miejsc          smallint not null
);

2. INDEXES

 trasy     |  CREATE UNIQUE INDEX trasy_pkey ON trasy USING btree
(id_trasy int4_ops)
 kursy     |  CREATE UNIQUE INDEX kursy_pkey ON kursy USING btree
(id_kursu int4_ops)
 kursy     |  CREATE INDEX ind_kurs_ ON kursy USING btree (id_trasy
int4_ops, data_kursu date_ops)

3. TEST

This time kursy has less rows:

saik=# EXPLAIN SELECT * from kursy where id_trasy=1 and
saik-# data_kursu=date('2001-12-12');
NOTICE:  QUERY PLAN:

Index Scan using ind_kurs_ on kursy  (cost=0.00..8.19 rows=1 width=14)

EXPLAIN
saik=# EXPLAIN SELECT * from kursy where id_trasy=1 
saik-# and data_kursu='2001-12-12'; 
NOTICE:  QUERY PLAN:

Index Scan using ind_kurs_ on kursy  (cost=0.00..2.02 rows=1 width=14)

I think that's all

Tomek


---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Reply via email to