Auf Thema antworten

um das mit dem funktionalen Index, Explain & einer besseren DB mal sehr einfach zu zeigen:


[code]

postgres=# create table obiast(ts timestamp);

CREATE TABLE

postgres=# create index idx_date on obiast (date_trunc('date',ts));

CREATE INDEX

postgres=#

postgres=#

postgres=# explain select * from obiast where date_trunc('date',ts) between current_date and current_date + 3;

                                                          QUERY PLAN                                                         

-------------------------------------------------------------------------------------------------------------------------------

 Bitmap Heap Scan on obiast  (cost=4.28..15.11 rows=11 width=8)

   Recheck Cond: ((date_trunc('date'::text, ts) >= CURRENT_DATE) AND (date_trunc('date'::text, ts) <= (CURRENT_DATE + 3)))

   ->  Bitmap Index Scan on idx_date  (cost=0.00..4.27 rows=11 width=0)

         Index Cond: ((date_trunc('date'::text, ts) >= CURRENT_DATE) AND (date_trunc('date'::text, ts) <= (CURRENT_DATE + 3)))

(4 rows)


postgres=#

[/code]


Zurück
Oben