Scan Operation Hints
Description
Specifies a scan operation, which can be tablescan, indexscan, index (same as indexscan) or indexonlyscan.
Syntax
1
|
[no] tablescan|indexscan|index|indexonlyscan|gsi|gsitable( [@queryblock] table [index]) |
Parameters
- no indicates that the specified hint will not be used for a join.
- For details about @queryblock, see Hint for Specifying the Query Block Where the Hint Is Located. This parameter can be omitted, indicating that it takes effect in the current query block.
- table specifies the table to be scanned. You can specify only one table. Use a table alias (if any) instead of a table name.
- [index] indicates the index for indexscan, index or indexonlyscan. You can specify only one index.

- indexscan, index, and indexonlyscan hints can be used only when the specified index belongs to the table.
- Scan operation hints can be used for row-store tables, HDFS tables, and subquery tables.
- The index-only scan plan can be generated by the index scan and index hints, but the index-only hint can generate only the index-only plan.
- When index scan and index is compatible with index-only scan, some plan changes may occur. For example, cost_model_version is added for escape. This parameter can be used to determine whether index scan is compatible with index-only scan. Index scan is compatible with index-only scan when the parameter value is greater than 2 or equal to 0.
- The centralized environment does not support GSI and GSI table hints.
Example
To specify an index-based hint for a scan, create an index named i on the i_item_sk column of the item table.
1
|
create index i on item(i_item_sk); |
Hint the query plan in Examples as follows:
1 2 3 4 5 |
explain select /*+ indexscan(item i) */ i_product_name product_name ... or EXPLAIN SELECT /*+ index(item i) */ i_product_name product_name ... |
item is scanned based on an index. The optimized plan is as follows.
-- Create a table.
create table gsi_test(a int, b int);
create index gsi_test_idx on gsi_test(a);
-- Use indexes.
gaussdb=# explain select /*+ gsi(gsi_test gsi_test_idx) */ * from gsi_test where b = 1;
WARNING: LINE 1: unsupport distributed hint at 'gsi'
QUERY PLAN
----------------------------------------------------------
Seq Scan on gsi_test (cost=0.00..36.86 rows=11 width=8)
Filter: (b = 1)
(2 rows)
gaussdb=# explain select /*+ gsitable(gsi_test gsi_test_idx) */ * from gsi_test where b = 1;
WARNING: LINE 1: unsupport distributed hint at 'gsitable'
QUERY PLAN
----------------------------------------------------------
Seq Scan on gsi_test (cost=0.00..36.86 rows=11 width=8)
Filter: (b = 1)
(2 rows)
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.