USE INDEX clause

USE INDEX clause

The USE INDEX clause supplies index hints that specify an index to use as part of the query execution. The query engine attempts to use the specified index if the index is applicable for the query.

use-index-clause:

USE INDEX ( index-ref [ , index-ref ]* )   

index-ref:

index-name [ index-using ]

index-name:

identifier

index-using:

USING ( VIEW | GSI )

Here's an example that shows how to use index hints. The example creates a GSI index called beer_abv, and then selects the name and abv fields, specifying that the query engine use the beer_abv index.

CREATE INDEX beer_abv ON `beer-sample`(abv) USING GSI;

SELECT name, abv FROM `beer-sample` USE INDEX (beer_abv USING GSI) WHERE abv > 10;			

The following example shows how to perform a similar query with a view index:

CREATE INDEX beer_abv ON `beer-sample`(abv) USING VIEW;

SELECT name, abv FROM `beer-sample` USE INDEX (beer_abv USING VIEW) WHERE abv > 10;