[Bug]: max_join_size and sql_big_selects do not enforce SELECT row-examination limits

Open
#33,279 0 comments 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 1 day

@matrix-meow is already working on this.

Since Nov 26, 2026.

Assessment

This issue has not been assessed yet.

Description

area/compatibility kind/bug needs-triage

Description

Reproduced on MatrixOne main commit c0cef5c9cce2164fedd201c188bfffe4d2d09a96 (git_version() = c0cef5c) and compared with MySQL 8.0.46.

MatrixOne accepts and reads back max_join_size and sql_big_selects, but does not enforce the SELECT row-examination limit. With max_join_size=1 and sql_big_selects=0, a three-row single-table SELECT, a three-row key JOIN, and a nine-row CROSS JOIN all execute normally. MySQL rejects all three corresponding statements with Error 1104.

This is not limited to JOIN syntax: the basic single-table case also bypasses the guard. A single-table COUNT(*) also executes on MatrixOne; MySQL permits that optimized aggregate too, so the aggregate is documented below as scope information rather than as a compatibility difference.

Minimal reproduction

DROP DATABASE IF EXISTS repro_max_join_size;
CREATE DATABASE repro_max_join_size;
USE repro_max_join_size;

CREATE TABLE t(id INT PRIMARY KEY, v INT);
INSERT INTO t VALUES(1,10),(2,20),(3,30);

SET SESSION sql_big_selects=0;
SET SESSION max_join_size=1;
SELECT @@session.max_join_size, @@session.sql_big_selects;
-- 1, 0

SELECT * FROM t;
-- MatrixOne: returns all three rows
-- MySQL 8.0.46: ERROR 1104 (42000)

SELECT COUNT(*) FROM t;
-- MatrixOne: 3
-- MySQL 8.0.46: 3 (optimized aggregate; not itself a divergence)

SELECT a.id,b.v
FROM t a JOIN t b ON a.id=b.id
ORDER BY a.id;
-- MatrixOne: returns (1,10),(2,20),(3,30)
-- MySQL 8.0.46: ERROR 1104 (42000)

SELECT a.id,b.id
FROM t a CROSS JOIN t b
ORDER BY a.id,b.id;
-- MatrixOne: returns all nine rows
-- MySQL 8.0.46: ERROR 1104 (42000)

SET SESSION sql_big_selects=1;
SELECT a.id,b.v
FROM t a JOIN t b ON a.id=b.id
ORDER BY a.id;
-- control: succeeds

MySQL 8.0.46 produces the following for the single-table statement while the limit is enabled:

ERROR 1104 (42000): The SELECT would examine more than MAX_JOIN_SIZE rows;
check your WHERE and use SET SQL_BIG_SELECTS=1 or SET MAX_JOIN_SIZE=#
if the SELECT is okay

Setting sql_big_selects=1 allows the query again, as documented.

Expected behavior

When SQL_BIG_SELECTS=OFF, MatrixOne must reject a SELECT whose estimated row examination exceeds MAX_JOIN_SIZE, using MySQL-compatible Error 1104 semantics. SQL_BIG_SELECTS=ON should bypass this particular limit. These variables must affect admission/planning rather than being writable no-ops.

MySQL documents the interaction here: https://dev.mysql.com/doc/refman/8.0/en/mysql-tips.html#safe-updates

Additional controls

  • A key-JOIN restricted to one result row succeeds.
  • The three-row key JOIN and nine-row CROSS JOIN both succeed immediately after sql_big_selects is set to 1.
  • As a separate session-variable control, sql_select_limit=2 does limit an unqualified three-row SELECT to two rows, and an explicit LIMIT 3 overrides it. Thus the result above is specific to the missing max_join_size enforcement.

Duplicate check

Searched max_join_size, sql_big_selects, ER_TOO_BIG_SELECT, and the Error 1104 text in open and closed issues; no existing report of the missing admission check was found.

Dominant language
Go
Stars
1.9k
Forks
312
Avg merge
22h 59m
Merged PRs (30d)
736

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from matrixorigin/matrixone

All issues in matrixorigin/matrixone

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.