SQL Query Error: Index Out of Range [0] with Length 0

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

Original topic: SQL查询报错index out of range [0] with length 0

| username: Ming

【TiDB Usage Environment】Production Environment
【TiDB Version】v7.1.0
【Encountered Problem: Problem Phenomenon and Impact】
An error occurs when executing a query statement: index out of range [0] with length 0
SQL:
select * from table limit 10;
Could you please explain why this error occurs?

| username: zhanggame1 | Original post link

Do you have a specific SQL query? Similar errors have occurred before, some bugs.
Executing select, prompt runtime error: index out of range [0] with length 0 - :ringer_planet: TiDB Technical Issues - TiDB Q&A Community (asktug.com)

| username: xfworld | Original post link

It could be a known bug, :rofl:

| username: ljluestc | Original post link

The error “index out of range [0] with length 0” usually indicates an attempt to access an element of an empty array or slice during indexing or slicing operations, while in reality, it has no elements. This is typically caused by a programming error, possibly related to the execution result of a query statement or data processing in the code.

In this case, a simple select * from table limit 10; query was executed, but this error was encountered. This could be due to one of the following reasons:

  1. Empty Table: If the “table” is empty, this query will return an empty result set because there is no data to return. Executing a limit query on an empty table might trigger this error.

  2. Table or Database Does Not Exist: If the “table” or the related database does not exist, executing the query will also raise this error.

  3. Query Execution Issue: If there is an issue with the database system itself, it might cause the query to fail to execute properly, resulting in an empty result set.

To resolve this issue, you can take the following steps:

  1. Ensure that the “table” exists and contains data. You can use a database client to execute SELECT COUNT(*) FROM table; to check if there is data in the table.

  2. Ensure that the query statement has no spelling errors and correctly specifies the table name and database name.

  3. Check if the TiDB cluster is running normally and there are no anomalies or errors. You can review TiDB logs for more information.

  4. If the “table” is empty, try querying other tables to ensure that the query works correctly. If other tables work fine, the issue might be related to the “table” itself.

| username: Jellybean | Original post link

Will it still report an error if you change the table name and query again?

Or try adding backticks ` to the table name in this SQL.

| username: zhanggame1 | Original post link

Does the table with the error have data?

| username: tidb菜鸟一只 | Original post link

Is it a partitioned table? It should be a bug.
query partition table with limit report runtime error: index out of range [0] with length 0 · Issue #45804 · pingcap/tidb (github.com)

| username: Ming | Original post link

If it’s SQL, it should be like this: limit 10. It should be a bug.

| username: Ming | Original post link

Yes, I saw the related issues.

| username: Ming | Original post link

There is data.

| username: Ming | Original post link

It should be a BUG.

| username: Ming | Original post link

Looking at the issues, it should involve v6.5 and v7.1

| username: system | Original post link

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