Basic SELECT queries result in data being disordered, and the index is inconsistent with KV data. How can this be fixed?

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 基本的select查询,数据都会混乱,索引与KV数据不一致,请问如何修复呢?

| username: zaker

【TiDB Usage Environment】Production Environment / Testing / PoC
【TiDB Version】5.2.4
【Encountered Problem】When performing a select query based on birthday, name, etc., no data is found. However, after adding a primary key, the query returns results, as shown in the image.
【Reproduction Path】Steps taken that led to the problem
【Problem Phenomenon and Impact】

【Attachment】

| username: WalterWj | Original post link

admin check this table

| username: zaker | Original post link

This will affect the production environment, right?

| username: WalterWj | Original post link

Check the official website. It shouldn’t, it just compares whether the index and data are consistent, without table lock. It’s better to run it during off-peak business hours.

| username: zaker | Original post link

Inconsistency, is there any way to fix the 8003 error code? Deleting and rebuilding the index is too time-consuming. This table has tens of billions of data.

| username: tidb狂热爱好者 | Original post link

Rebuild the index first. You can name it something else initially, then rename it after execution.

| username: BraveChen | Original post link

First, set this index as an invisible index, CREATE INDEX | PingCAP Docs, so that your production environment SQL will no longer use it, as the data is inconsistent. Second, recreate the index. In TiDB, it is an online DDL, which will not lock the table and affect your use of the table. Third, delete the problematic index.

| username: zaker | Original post link

:+1::+1::+1: Thanks a lot

| username: zaker | Original post link

:+1: :+1: Last time we used this solution for inconsistency, adding the index was relatively slow. There might be a small portion of data that didn’t match. Is it possible to repair the index for this small portion of data?

| username: Lucien-卢西恩 | Original post link

There should be no such way. Rebuilding the index also helps with the performance of index queries for future data, as it can reduce the previous skip key performance issues.

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.