cockroachdb / cockroachdb/cockroach
`UNION` with `ORDER BY` and `LIMIT` produced wrong result in multi-node version but not in single-node version (1)
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
**Describe the problem**
`UNION` with `ORDER BY` and `LIMIT` produced wrong result in multi-node version but not in single-node version
**To Reproduce**
First execute `init.sql` to create the table. Then executing `error.sql` yields unexpected results. Note that reproducing these results might not be entirely stable. Typically, it can be completed within three attempts. You can try executing multiple times or execute it again after rebuilding the table.
[init.sql.txt](https://github.com/cockroachdb/cockroach/files/15090483/init.sql.txt)
[error.sql.txt](https://github.com/cockroachdb/cockroach/files/15090481/error.sql.txt)
**Expected behavior**
The multi-node version of CockroachDB produced incorrect results. The correct result should have only been one line, but it outputted 48 lines instead.
[output_re_main.log](https://github.com/cockroachdb/cockroach/files/15103696/output_re_main.log)
[output_re_single.log](https://github.com/cockroachdb/cockroach/files/15103697/output_re_single.log)
**Environment:**
- CockroachDB version: 23.1.9
- Server OS: `Linux a002 6.5.0-18-generic #18~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Feb 7 11:40:03 UTC 2 x86_64 x86_64 x86_64 GNU/Linux`
- Client app: postgresql odbc/psql
docker compose file:
```
version: '3.5'
services:
crdb1:
image: cockroachdb/cockroach:v23.1.19
command: "start --advertise-addr=crdb1:26357 --http-addr=crdb1:8080 --listen-addr=crdb1:26357 --sql-addr=crdb1:26257 --insecure --join=crdb1:26357,crdb2:26357,crdb3:26357"
volumes:
- "crdb1_data:/cockroach/cockroach-data"
networks:
crnet:
ipv4_address: 10.0.5.11
crdb2:
image: cockroachdb/cockroach:v23.1.19
command: "start --advertise-addr=crdb2:26357 --http-addr=crdb2:8080 --listen-addr=crdb2:26357 --sql-addr=crdb2:26257 --insecure --join=crdb1:26357,crdb2:26357,crdb3:26357"
volumes:
- "crdb2_data:/cockroach/cockroach-data"
networks:
crnet:
ipv4_address: 10.0.5.12
crdb3:
image: cockroachdb/cockroach:v23.1.19
command: "start --advertise-addr=crdb3:26357 --http-addr=crdb3:8080 --listen-addr=crdb3:26357 --sql-addr=crdb3:26257 --insecure --join=crdb1:26357,crdb2:26357,crdb3:26357"
volumes:
- "crdb3_data:/cockroach/cockroach-data"
networks:
crnet:
ipv4_address: 10.0.5.13
crdb_single:
image: "cockroachdb/cockroach:v23.1.19"
command: start-single-node --insecure
volumes:
- "crdb_single_data:/cockroach/cockroach-data"
networks:
crnet:
ipv4_address: 10.0.5.21
volumes:
crdb1_data:
crdb2_data:
crdb3_data:
crdb_single_data:
networks:
crnet:
driver: bridge
ipam:
config:
- subnet: 10.0.5.0/24
gateway: 10.0.5.254
```
#### about us
We are the BASS team from the School of Cyber Science and Technology at Beihang University. Our main focus is on system software security, operating systems, and program analysis research, as well as the development of automated program testing frameworks for detecting software defects. Using our self-developed database vulnerability testing tool, we have identified the above-mentioned possible vulnerabilities that may lead to database logic error.
Jira issue: CRDB-38140
Contributor guide
Assessment
This issue has not been assessed yet.