-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SQL_CALC_FOUND_ROWS behavior leads to data truncation #14448
Comments
We can check from the document:
|
Hi,@wwar |
If you want, you can join the pingcap.com/tidbslack and discuss with others. |
@XuHuaiyu It does parse-but-ignore, but then it populates My concern is that it is a silent data truncation issue, due to how the functionality is most commonly used. It is not good to bury it in the docs, because you can not rely on someone seeing it and understanding what it really means. My usage of TiDB is currently purely hobby. It might turn professional at some point, I will try and join the slack when I get a chance :-) Thank you for the invitation. |
Verifying this still exists in master: DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(2),(3);
SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1;
SELECT FOUND_ROWS();
..
mysql> SELECT FOUND_ROWS();
+--------------+
| FOUND_ROWS() |
+--------------+
| 1 |
+--------------+
1 row in set (0.00 sec)
mysql> SELECT tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v4.0.0-beta.2-798-gd941ff5cc
Edition: Community
Git Commit Hash: d941ff5cc8b4babf9dcfdd91b66a5c53b798c122
Git Branch: master
UTC Build Time: 2020-07-18 05:54:02
GoVersion: go1.13
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
1 row in set (0.00 sec) |
Updating to match the severity of #19383 (a similarly unsafe parse but ignore issue). |
Integrity check: |
Please edit this comment to complete the following informationBugNote: Make Sure that 'component', and 'severity' labels are added 1. Root Cause Analysis (RCA)TiDB parses but ignores the flag 2. SymptomAny query that includes the flag 3. All Trigger ConditionsThe results are only wrong if the actual count is > the limit count, which might make it difficult to understand TiDB is wrong in simple cases. 4. Workaround (optional)TiDB does not support this feature, so the workaround is that users should issue two queries. The first query retrieves the first N rows, the second query retrieves the count of rows. 5. Affected versions[2.1.0,2.1.99],[3.0.0,3.0.99],[3.1.0,3.1.99],[4.0.0,4.0.99] 6. Fixed versionsunplaned |
Bug Report
Please answer these questions before submitting your issue. Thanks!
There is an open bug on SQL_CALC_FOUND_ROWS: #8235
I am not sure if it is well understood how serious this is. Here is a small test case:
In MySQL:
In TiDB:
The most common use-case for this feature is that applications show the first few results (lets say LIMIT 100 rows) and then paginate to show a count of total results. Because the TiDB behavior is to return the same number of rows as the LIMIT, the application will incorrectly think that there is only one page of results.
This query is used in Wordpress, Drupal, and all number of MySQL applications. It is deprecated in MySQL 8.0, but I suspect based on popularity will not be removed for some time.
Assuming that #8235 is not fixed, I would like to instead propose similar handling to #10065 where it is an error by default when attempting to execute this query, with an option to skip the error and downgrade to a warning.
It is not safe to just return a warning for two reasons:
What version of TiDB are you using (
tidb-server -V
or runselect tidb_version();
on TiDB)?The text was updated successfully, but these errors were encountered: