Why is this simple SQL considered a Cartesian product?

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

Original topic: 为什么这条简单的SQL会被认为是笛卡尔乘积?

| username: TiDBer_mG4qjkfV

[TiDB Usage Environment] Test
[TiDB Version] v6.1.1
[Encountered Problem]
Why is a simple query statement considered a Cartesian product?

select min(k), max(k) from mytable;

Error: ERROR 8110 (HY000): Cartesian product is unsupported

[Reproduction Path]
[Problem Phenomenon and Impact]

| username: h5n1 | Original post link

Please provide the table structure and the explain result.

| username: TiDBer_mG4qjkfV | Original post link

The table structure is attached in the image, and the explain command doesn’t work. It should be a restriction set by the DBA.

| username: xfworld | Original post link

Found another bug~ Congratulations

| username: TiDBer_mG4qjkfV | Original post link

Huh? It’s only my first day using TiDB today. And there’s already a bug?

| username: h5n1 | Original post link

SHOW CREATE TABLE statement

| username: TiDBer_mG4qjkfV | Original post link

The image is not visible. Please provide the text you need translated.

| username: 人如其名 | Original post link

Modify the related configuration parameters of TiDB:

Note that the following operation requires restarting the TiDB instance!!!
Remove the performance.cross-join: false in the picture
Then run tiup cluster reload -R tidb

Then check the execution plan of the table again?

| username: TiDBer_mG4qjkfV | Original post link

The image you provided is not visible. Please provide the text you need translated.

| username: 人如其名 | Original post link

The optimizer in the logical optimization phase converts the process of obtaining max() and min() through an index into two topN operations followed by a cross join. After logical optimization, it checks whether the SQL after logical optimization contains a cross join and whether performance.cross-join=false is set. If so, it will report the error you just mentioned. I think this can be understood as a bug in the optimizer, after all, the cross join is generated by the optimizer’s own logical optimization, not by user behavior. A temporary workaround is to remove the performance.cross-join=false configuration parameter. Go ahead and file an issue.

| username: 人如其名 | Original post link

Bro, on your first day, you were already modifying parameters and restarting the data. That’s impressive! On my first day, I couldn’t even understand the concept of HTAP…

| username: TiDBer_mG4qjkfV | Original post link

Okay, big brother, thank you very much! I find it easy to understand operational tasks like changing configurations :grin:. Let’s learn from each other :handshake: :handshake: :handshake:

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

Congratulations on finding the bug.

| username: OnTheRoad | Original post link

Learned about another pitfall.

| username: 近墨者zyl | Original post link

Learning, learning.

| username: alfred | Original post link

Congratulations on finding the bug.