You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] FOUND_ROWS() returns incorrect row count after SELECT and SQL_CALC_FOUND_ROWS #27304
DROPDATABASE IF EXISTS found_rows_test;
CREATEDATABASEfound_rows_test;
USE found_rows_test;
CREATETABLEt(id INT);
INSERT INTO t VALUES (1), (2), (3);
SELECT SQL_CALC_FOUND_ROWS *FROM t LIMIT1;
SELECT FOUND_ROWS() AS after_calc;
SELECT*FROM t LIMIT2;
SELECT FOUND_ROWS() AS after_plain;
Prepared Statement 也可以复现普通查询问题:
PREPARE ps FROM'SELECT * FROM t LIMIT 2';
EXECUTE ps;
SELECT FOUND_ROWS() AS prepared_after_plain;
DEALLOCATE PREPARE ps;
Regression and extended verification for #27304 (2026-09-10)
Verification Environment
MatrixOne source: local origin/main at 401b967dc15a45a4374a04921b2bb2c9fbdb7117 — test: synchronize cross-CN FK regression setup (#28511).
The running mo-service binary was rebuilt from that commit and restarted before verification; mo-service -version reported 401b967dc1.
Topology: 2 CN / 1 TN / 1 Log service / Proxy.
Tested endpoints: Proxy 127.0.0.1:6001, CN1 127.0.0.1:16001, and CN2 127.0.0.1:16002; each accepted a fresh connection and SELECT 1.
Client protocol: MySQL wire protocol through the mysql client and MOTR. The prepared coverage uses SQL PREPARE / EXECUTE, which is the issue's reported form.
OK — Original SQL_CALC_FOUND_ROWS scenario returned FOUND_ROWS() = 3 after LIMIT 1 on a three-row table, through Proxy 6001, CN1 16001, and CN2 16002.
OK — Plain SELECT ... LIMIT 2 returned FOUND_ROWS() = 2 through all three endpoints.
OK — SQL PREPARE / EXECUTE for SELECT ... LIMIT 2 returned FOUND_ROWS() = 2; reusing the prepared statement preserved the same value.
OK — Boundary cases: LIMIT 0 after SQL_CALC_FOUND_ROWS returned 3, OFFSET retained the pre-limit count 3, and an empty result returned 0.
OK — A successful status statement and a failed missing-table statement did not overwrite the previous successful FOUND_ROWS() = 2.
OK — The original scenarios used isolated endpoint-specific databases and ran concurrently across Proxy 6001, CN1 16001, and CN2 16002.
OK — MOTR recording passed through Proxy 6001; replay passed through Proxy 6001, CN1 16001, and CN2 16002, with 28/28 assertions at each endpoint.
Not covered — Binary COM_STMT_PREPARE / COM_STMT_EXECUTE; it is outside the reported SQL PREPARE / EXECUTE reproduction.
Findings
The linked fix correctly publishes the preceding user-visible result-set count as session state. The original scenario, normal LIMIT, SQL prepared execution, boundary cases, and error/status preservation all behaved as expected on each verified endpoint.
No additional large-data MOTR regression is needed: this defect is per-session result-count state rather than a row-volume, block/batch, spill, concurrency, skew, network, or resource-scale condition. The linked product regression already covers the cross-CN path with 100000 rows.
Final Conclusion
Fixed. The repaired behavior is verified on the rebuilt latest origin/main runtime through the full 2 CN / 1 TN / 1 Log service / Proxy topology and all three endpoints. No additional large-data regression is required for the reasons above.
Regression alert — the incorrect FOUND_ROWS behavior reported here has reappeared on current main. Reproduced 2026-10-29 on main c6683bd2f5 (commit built and launched locally today, dual-CN with proxy — same topology class as the 2026-09-10 verification upthread):
-- table: exx.t(id INT PRIMARY KEY, k INT), 50 rows loaded, secondary index on k-- ground truth (verified via plain SELECT COUNT): WHERE k=3 matches 22 rowsSELECT SQL_CALC_FOUND_ROWS id FROMexx.tWHERE k =3LIMIT2; -- returns 2 rows (correct)SELECT FOUND_ROWS();
-- MO today: 7 ← wrong. Expect 22. Neither the LIMIT count (2) nor anything derivable; -- 7 matches the mo_table_stats-style cardinality estimate (50%-ish buckets of the index),-- i.e. FOUND_ROWS is again backed by table statistics, not the SQL_CALC_FOUND_ROWS tuple count.-- adjacent checks from the same session:SELECT id FROMexx.tWHERE k =3LIMIT2; SELECT FOUND_ROWS(); -- 2 (correct, plain-path)UPDATEexx.tSET v=v WHERE id=1; SELECT ROW_COUNT(); -- 0, MySQL says 1 (touched row)CREATETABLEexx.tmp1(id INT); SELECT FOUND_ROWS(); -- 1, should be 0 after DDL
The closed-at status (verified on 401b967dc1, 2026-09-10) does not hold on c6683bd2f5. Since the estimate-shaped value (7 for a 22-row truth) is exactly the "statistics-backed FOUND_ROWS" signature this issue originally described, whatever fix landed for the COUNT path did not cover (or regressed for) the SQL_CALC_FOUND_ROWS + indexed-column + LIMIT combination. Happy to cut a fresh standalone report if preferred — flagging here first since the case was verified-closed recently and the thread's history is the best context for the fix owners.
Activity
fix: return correct values from FOUND_ROWS() (#27312)
slyunnn commentedon Sep 10, 2026
Regression and extended verification for #27304 (2026-09-10)
Verification Environment
origin/mainat401b967dc15a45a4374a04921b2bb2c9fbdb7117—test: synchronize cross-CN FK regression setup (#28511).mo-servicebinary was rebuilt from that commit and restarted before verification;mo-service -versionreported401b967dc1.2 CN / 1 TN / 1 Log service / Proxy.127.0.0.1:6001, CN1127.0.0.1:16001, and CN2127.0.0.1:16002; each accepted a fresh connection andSELECT 1.mysqlclient and MOTR. The prepared coverage uses SQLPREPARE/EXECUTE, which is the issue's reported form.a9d02fd3b4417f1e781e24f59bc580d6cdee0358, merged by #27312,fix: return correct values from FOUND_ROWS().What Was Covered
SQL_CALC_FOUND_ROWSscenario returnedFOUND_ROWS() = 3afterLIMIT 1on a three-row table, through Proxy6001, CN116001, and CN216002.SELECT ... LIMIT 2returnedFOUND_ROWS() = 2through all three endpoints.PREPARE/EXECUTEforSELECT ... LIMIT 2returnedFOUND_ROWS() = 2; reusing the prepared statement preserved the same value.LIMIT 0afterSQL_CALC_FOUND_ROWSreturned3,OFFSETretained the pre-limit count3, and an empty result returned0.FOUND_ROWS() = 2.6001, CN116001, and CN216002.6001; replay passed through Proxy6001, CN116001, and CN216002, with28/28assertions at each endpoint.COM_STMT_PREPARE/COM_STMT_EXECUTE; it is outside the reported SQLPREPARE/EXECUTEreproduction.Findings
The linked fix correctly publishes the preceding user-visible result-set count as session state. The original scenario, normal
LIMIT, SQL prepared execution, boundary cases, and error/status preservation all behaved as expected on each verified endpoint.MOTR / BVT Coverage
test/issue-27304-found-rows.ef5e14d4de09bc5bdba66c8729dfd8e92fc31eee,test: add MOTR regression for #27304.suites/14_issue_regression/t/issue_27304_found_rows.testwith its recorded result file.#155, cherry-pick commite27c7301ffc390ad2b822841fe56d090c09477eb.100000rows.Final Conclusion
Fixed. The repaired behavior is verified on the rebuilt latest
origin/mainruntime through the full2 CN / 1 TN / 1 Log service / Proxytopology and all three endpoints. No additional large-data regression is required for the reasons above.fix: return correct values from FOUND_ROWS() (matrixorigin#27312)
fix: return correct values from FOUND_ROWS() (matrixorigin#27312)
fix: return correct values from FOUND_ROWS() (matrixorigin#27312)
Ariznawlll commentedon Oct 29, 2026
Regression alert — the incorrect FOUND_ROWS behavior reported here has reappeared on current main. Reproduced 2026-10-29 on main
c6683bd2f5(commit built and launched locally today, dual-CN with proxy — same topology class as the 2026-09-10 verification upthread):The closed-at status (verified on
401b967dc1, 2026-09-10) does not hold onc6683bd2f5. Since the estimate-shaped value (7 for a 22-row truth) is exactly the "statistics-backed FOUND_ROWS" signature this issue originally described, whatever fix landed for the COUNT path did not cover (or regressed for) theSQL_CALC_FOUND_ROWS+ indexed-column + LIMIT combination. Happy to cut a fresh standalone report if preferred — flagging here first since the case was verified-closed recently and the thread's history is the best context for the fix owners.