sql - Creating indexes on two columns to check if a date falls between those two -


i'm using laravel 5 , postgres. there table has 2 columns 'start_date' , 'end_date'. want create index can check if date falls in between two.

i'm using following code that

$table->date ( 'start_date' ); $table->index('start_date');  $table->date ( 'end_date' ); $table->index('end_date'); 

but saw there option create compound index too.

my question best way create indexes above scenario?

depends on queries are. while other databases mysql can use 1 index per table in situations postgresql can use more one.

thus if have 2 separate indexes on start_date , end_date chances both used if close has conditions both columns. note there isn't guarantee both indices or 1 of them might used. example if have few rows faster retrieve data directly without referring index. in situation having composite index wouldn't of use either.

if have other queries involve 1 of 2 columns, again better off 2 separate indexes


Comments

Popular posts from this blog

wireshark - USB mapping with python -

c++ - nodejs socket.io closes connection before upgrading to websocket -

Deploying Qt Application on Android is really slow? -