TiDB 5.2 Query Data, Values Keep Changing (All Programs Closed, No Other Connections to Database)

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

Original topic: tidb5.2 查询数据,数值总变(程序已经全部关闭,没有其他人连接数据库)

| username: RAIN

【TiDB Usage Environment】Production
【TiDB Version】5.2
【Encountered Problem】Querying data, values keep changing (all programs have been closed, no one else is connected to the database)
【Reproduction Path】Operations performed that led to the problem: Query operation
【Problem Phenomenon and Impact】

| username: Kongdom | Original post link

Is it possible that not all fields are covered in the group by clause?

| username: RAIN | Original post link

This has nothing to do with group by. Even without group by, querying the same record at different times yields different values.

| username: h5n1 | Original post link

Could you post a few individual query results for us to take a look?

| username: RAIN | Original post link

This is a query statement. Except for the time which is datetime, all others are varchar.

| username: RAIN | Original post link

Here is the query statement I posted. Could you write a query for me to try?

| username: Mingdr | Original post link

It’s normal for the data to change. If the fields not included in the group by clause don’t use aggregate functions, aren’t they taken randomly?

| username: h5n1 | Original post link

Where did you post that single-row query without the group by clause?

| username: Kongdom | Original post link

Yes, it matters. According to development standards, fields outside of aggregate functions must be included in the GROUP BY clause.

| username: RAIN | Original post link

In the TiDB test environment, there are no issues with the query, but in the production environment, it looks like this. Here are the screenshots without the group by clause:

| username: RAIN | Original post link

In the test environment, with the same data and the same query statement, the query results are consistent.

| username: OnTheRoad | Original post link

Regarding development standards, we strictly require that the in the group by clause must be consistent with the in the select clause.

| username: Kongdom | Original post link

Could you provide the table structure and desensitized reproducible data? We will try to reproduce it.

| username: db_user | Original post link

Try removing the aggregate function (max) and see the result. It must be randomly selected.