Does the same query use different indexes?

Can a select query use different indexes if the value of the where clause is changed?

The next two queries use different indexes, and the only difference is the value of the condition and typeenvoi = 'EXPORT' or or typeenvoi = 'MAIL'

select numenvoi,adrdest,nomdest,etat,nbessais,numappel,description,typeperiode,datedebut,datefin,codeetat,codecontrat,typeenvoi,dateentree,dateemission,typedoc,numdiffusion,nature,commentaire,criselcomp,crisite,criservice,chrono,codelangueetat,piecejointe, sujetmail, textemail
            from v_envoiautomate
            where etat=0 and typeenvoi='EXPORT'
            and nbessais<1 


select numenvoi,adrdest,nomdest,etat,nbessais,numappel,description,typeperiode,datedebut,datefin,codeetat,codecontrat,typeenvoi,dateentree,dateemission,typedoc,numdiffusion,nature,commentaire,criselcomp,crisite,criservice,chrono,codelangueetat,piecejointe, sujetmail, textemail
            from v_envoiautomate
            where etat=0 and typeenvoi='MAIL'
            and nbessais<1

Can someone give me an explanation?

+5
source share
3 answers

Index details are stored as statistics in a histogram type dataset in SQL Server.

Each index is placed in ranges, and each range contains a summary of key values ​​in this range, for example:

  • high value range
  • number of values ​​in the range
  • ()
  • ,

... ..

:

DBCC SHOW_STATISTICS(<tablename>, <indexname>)

, , , , , , .

where, , , . , , .

, , , + , , .

, , ; SQL Server , . , .

, , typeenvoi . , , , , , , .

+8

SQL Server ( ) , " ". -. , , , .

, . :

  • .

"MAIL" "EXPORT" , . , .

+4

, "", , . , , , SQL Server , . , , "MAIL", , , . "EXPORT", "EXPORT" etat 0, , , .

+2

All Articles