If data whose primary keys are out of the specified range is returned when the GetRange operation is called to read data, you can create a secondary index to read data whose primary keys are only within the specified range.
Problem description
When the GetRange operation is called to perform range query in the Tablestore console or by using Tablestore SDKs, query the external tables of Tablestore, or synchronize data from Tablestore by using Tablestore Reader, data whose primary keys are out of the specified range is returned.
Possible cause
The specified query conditions do not comply with the leftmost matching principle.
For example, if a data table contains two primary key columns, beginPrimaryKey = INF_MIN
and endPrimaryKey = INF_MAX
are specified for the first primary key column, and beginPrimaryKey = 10
and endPrimaryKey = 10
are specified for the second primary key column, all data in the table, instead of
only the rows in which the second primary key column value is 10, is returned.
Solution
- To query data within a specified range in the Tablestore console or by using specific SDKs, use the secondary index. For more information about specific operations, see Read data in the console and Read data by using SDKs.
- To query data within a specified range in a Tablestore external table, set the table name to the secondary index name in the SQL statement that is executed to create the external table. For more information, see Access Tablestore data.
- To synchronize data within a specified range from Tablestore by using Tablestore Reader, set the table name to the secondary index name in the data synchronization script. For more information about specific operations, see Tablestore Reader.