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

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -