Skip to content

[Bug]: Select ... limit 0, 18446744073709551615 in MO throws an error only int64 support in limit/offset clause while the same sql executes successfully in both mysql 5.7 and 8.0 #16624

Closed

Description

@aronchanisme

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

1.2-dev

Commit ID

d36f889

Other Environment Information

- Hardware parameters: 8c 16g
- OS type: All Linux and Mac Distrubutions
- Others: all

Actual Behavior

  1. In MO
github@test0-10-222-4-0:/data/mo/1.2-dev/matrixone$ mo_ctl connect
2024-06-04 14:18:55.439 UTC+0800    [INFO]    Checking connectivity
2024-06-04 14:18:55.529 UTC+0800    [INFO]    Ok, connecting for user ... 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4662
Server version: 8.0.30-MatrixOne-v3688943 MatrixOne

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database test;
Query OK, 1 row affected (0.02 sec)

mysql> use test;
Database changed
mysql> show tables;
Empty set (0.00 sec)

mysql> create table t1(id int);
Query OK, 0 rows affected (0.03 sec)

mysql> select * from t1 limit 0, 18446744073709551615;
ERROR 1149 (HY000): SQL syntax error: only int64 support in limit/offset clause
mysql> select git_version();
+---------------+
| git_version() |
+---------------+
| d36f88943     |
+---------------+
1 row in set (0.00 sec)
  1. In MySQL 5.7.42
root@mo-sz-0:~# mysql57 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.42 MySQL Community Server (GPL)

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database test;
Query OK, 1 row affected (0.00 sec)

mysql> use test;
Database changed
mysql> create table t1(id int);
Query OK, 0 rows affected (0.01 sec)

mysql> select * from t1 limit 0, 18446744073709551615;
Empty set (0.00 sec)

mysql> select version();
+-----------+
| version() |
+-----------+
| 5.7.42    |
+-----------+
1 row in set (0.00 sec)
  1. In MySQL 8.0.31
root@mo-sz-0:~# mysql80 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.31 MySQL Community Server - GPL

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> drop table t1;
Query OK, 0 rows affected (0.02 sec)

mysql> create table t1(id int);
Query OK, 0 rows affected (0.03 sec)

mysql> select * from t1 limit 0, 18446744073709551615;
Empty set (0.00 sec)

mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.31    |
+-----------+
1 row in set (0.00 sec)

Expected Behavior

MO behaves the same as what MySQL does.

Steps to Reproduce

create database if not exists test;
use test;
drop table if exists t1;
create table t1(id int);
select * from t1 limit 0, 18446744073709551615;

Additional information

As per https://dev.mysql.com/doc/refman/8.4/en/select.html, limit can take up to 2 parameters (Offset, Limit) , and the limit value can be set to a very large one in order to retrieve all rows from a table(in case you don't know the number of rows in that table).

To retrieve all rows from a certain offset up to the end of the result set, you can use some large number for the second parameter. This statement retrieves all rows from the 96th row to the last:

SELECT * FROM tbl LIMIT 95,18446744073709551615;

Activity

  1. added this to the 1.2.1 milestone on Jun 4, 2024
  2. daviszhen commented on Jun 4, 2024

    @daviszhen
    Contributor

    数值越界

  3. aronchanisme commented on Jun 4, 2024

    @aronchanisme
    ContributorAuthor

    2^64 = 18446744073709551616 which is exactly 1 larger than the given limit number 18446744073709551615.
    In MySQL 8.0.31, it seems like only limit number less than or equal to 18446744073709551615 is allowed, otherwise mysql will thows an syntax error expection.

    mysql> select version();
    +-----------+
    | version() |
    +-----------+
    | 8.0.31    |
    +-----------+
    1 row in set (0.00 sec)
    
    mysql> select * from t1 limit 0, 18446744073709551616;
    ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '18446744073709551616' at line 1
    mysql> select * from t1 limit 0, 18446744073709551615;
    Empty set (0.00 sec)
    
    mysql> select * from t1 limit 0, 18446744073709551617;
    ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '18446744073709551617' at line 1
    mysql> select * from t1 limit 0, 18446744073709551614;
    Empty set (0.00 sec)
    
    mysql> select * from t1 limit 0, 18446744073709551615;
    Empty set (0.00 sec)
    
    mysql> select * from t1 limit 0, 18446744073709551618;
    ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '18446744073709551618' at line 1

    Corresponding mo source code:

    return nil, moerr.NewSyntaxError(b.GetContext(), "only int64 support in limit/offset clause")

  4. daviszhen commented on Jun 5, 2024

    @daviszhen
    Contributor

    pr中

  5. daviszhen commented on Jun 6, 2024

    @daviszhen
    Contributor

    pr中

  6. daviszhen commented on Jun 7, 2024

    @daviszhen
    Contributor

    pr中

  7. aronchanisme commented on Jun 9, 2024

    @aronchanisme
    ContributorAuthor

    Fixed in main(1790d7e63) and 1.2-dev(4d3b371e4). Bvt cases are also added. Closing it as completed.

    1. main
    github@test0-10-222-4-0:/data/mo/main/matrixone$ mo_ctl connect
    2024-06-09 16:19:51.092 UTC+0800    [INFO]    Checking connectivity
    2024-06-09 16:19:51.176 UTC+0800    [INFO]    Ok, connecting for user ... 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 3209
    Server version: 8.0.30-MatrixOne-v1790763 MatrixOne
    
    Copyright (c) 2000, 2024, Oracle and/or its affiliates.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql> create database if not exists test;
    Query OK, 1 row affected (0.03 sec)
    
    mysql> use test;
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    
    Database changed
    mysql> drop table if exists t1;
    Query OK, 0 rows affected (0.06 sec)
    
    mysql> create table t1(id int);
    
    Query OK, 0 rows affected (0.02 sec)
    
    mysql> select * from t1 limit 0, 18446744073709551615;
    Empty set (0.00 sec)
    
    mysql> select git_version();
    +---------------+
    | git_version() |
    +---------------+
    | 1790d7e63     |
    +---------------+
    1 row in set (0.00 sec)
    
    mysql> system mo_ctl get_branch
    2024-06-09 16:20:19.885 UTC+0800    [INFO]    Try get mo branch
    2024-06-09 16:20:19.939 UTC+0800    [INFO]    Get branch succeeded, current branch: main
    mysql> system mo_ctl get_cid
    2024-06-09 16:20:24.109 UTC+0800    [INFO]    Try get mo commit id
    commit 1790d7e63bfaf1e28b942e9fbc2684c1ae6a8637
    Author: gouhongshen <[email protected]>
    Date:   Sat Jun 8 15:57:35 2024 +0800
    
        refactor the block reader filter to support more expressions (#16756)
        
        1.  `>, >=, <, <=`
        2. `between and, prefix in, prefix between, prefix eq`
        3. `in, eq`
        
        Approved by: @XuPeng-SH, @aressu1985
    2024-06-09 16:20:24.161 UTC+0800    [INFO]    Get commit id succeeded
    1. 1.2-dev
    github@test0-10-222-4-0:/data/mo/1.2-dev/matrixone$ mo_ctl connect
    2024-06-09 16:25:30.801 UTC+0800    [INFO]    Checking connectivity
    2024-06-09 16:25:30.896 UTC+0800    [INFO]    Ok, connecting for user ... 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 6302
    Server version: 8.0.30-MatrixOne-v433714 MatrixOne
    
    Copyright (c) 2000, 2024, Oracle and/or its affiliates.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql> create database if not exists test;
    Query OK, 1 row affected (0.03 sec)
    
    mysql> use test;
    
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    
    Database changed
    mysql> drop table if exists t1;
    Query OK, 0 rows affected (0.04 sec)
    
    mysql> create table t1(id int);
    Query OK, 0 rows affected (0.02 sec)
    
    mysql> select * from t1 limit 0, 18446744073709551615;
    Empty set (0.00 sec)
    
    mysql> select git_version();
    +---------------+
    | git_version() |
    +---------------+
    | 4d3b371e4     |
    +---------------+
    1 row in set (0.01 sec)
    
    mysql> system mo_ctl get_branch
    2024-06-09 16:25:46.208 UTC+0800    [INFO]    Try get mo branch
    2024-06-09 16:25:46.265 UTC+0800    [INFO]    Get branch succeeded, current branch: 1.2-dev
    mysql> system mo_ctl get_cid
    2024-06-09 16:25:48.870 UTC+0800    [INFO]    Try get mo commit id
    commit 4d3b371e492dc8f3caef12a2f0ac96cfdc8c3f7a
    Author: reusee <[email protected]>
    Date:   Sun Jun 9 15:29:30 2024 +0800
    
        fileservice: fix fd leak in LocalFS.read (#16749)
        
        fix fd leak in LocalFS.read
        
        Approved by: @fengttt, @sukki37
    2024-06-09 16:25:48.936 UTC+0800    [INFO]    Get commit id succeeded
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions