vitessio / vitess

Vitess is a database clustering system for horizontal scaling of MySQL.
http://vitess.io
Apache License 2.0
18.23k stars 2.07k forks source link

Bug Report: Error from query with duplicate select statement #13181

Closed arvind-murty closed 1 year ago

arvind-murty commented 1 year ago

Overview of the Issue

The query select /*vt+ PLANNER=Gen4 */ count(*), count(*), count(*) from t1 as tbl0, t2 as tbl1 where tbl0.shardKey = tbl1.shardKey group by tbl1.id order by tbl1.id produces the following error: EOF (errno 2013) (sqlstate HY000).

This was found using a modified aggregation/fuzz_test.go: https://github.com/vitessio/vitess/commit/dee5e43f731e036ffd8c771ab571cb2103fd5c0f#diff-0d61aeaf2470a17624e36cdc59be406ef066f3fec2d81af0c40f854c61e0386e.

Reproduction Steps

  1. Deploy the following vschema:
    {
    "sharded": true,
    "vindexes": {
    "hash": {
      "type": "hash"
    }
    },
    "tables": {
    "t1": {
      "column_vindexes": [
        {
          "column": "shardKey",
          "name": "hash"
        }
      ]
    },
    "t2": {
      "column_vindexes": [
        {
          "column": "shardKey",
          "name": "hash"
        }
      ]
    }
    }
    }
  2. Deploy the following schema:
    
    CREATE TABLE t1 (
    t1_id bigint unsigned NOT NULL,
    `name` varchar(20) NOT NULL,
    `value` varchar(50),
    shardKey bigint,
    PRIMARY KEY (t1_id)
    -- UNIQUE KEY `t1id_name` (t1_id, `name`),
    -- KEY `IDX_TA_ValueName` (`value`(20), `name`(10))
    ) ENGINE InnoDB;

CREATE TABLE t2 ( id bigint NOT NULL, shardKey bigint, PRIMARY KEY (id) ) ENGINE InnoDB;

3. Insert data:

insert into t1 (t1_id, name, value, shardKey) values (0, 'name0', 'value0', 0), (1, 'name1', 'value1', 1), (2, 'name2', 'value2', 2); insert into t2 (id, shardKey) values (0, 0), (1, 1);

4. Run `select /*vt+ PLANNER=Gen4 */ count(*), count(*), count(*) from t1 as tbl0, t2 as tbl1 where tbl0.shardKey = tbl1.shardKey group by tbl1.id order by tbl1.id`

### Binary Version

```sh
% vtgate --version
Version: 17.0.0-SNAPSHOT (Git revision bedcf510f1876e781445228a52f90a16891a5503 branch 'am-query-gen') built on Sun May 28 21:08:28 PDT 2023 by arvindmurty@arvinds-mbp.lan using go1.20.4 darwin/arm64

Operating System and Environment details

OS: macOS 12.5
Kernel: Darwin 21.6.0
Architecture: arm64

Log Fragments

vtgate-stderr.txt:

W0528 20:57:00.096067   60966 log.go:39] Failed to read in config : Config File "vtconfig" Not Found in "[/Users/arvindmurty/go/src/vitess.io/vitess/go/test/endtoend/vtgate/queries/aggregation]"
W0528 20:57:00.112665   60966 vschema.go:108] The V3 planner is deprecated and will be removed in V17 of Vitess
W0528 20:57:30.115292   60966 tabletgateway.go:199] Timeout waiting for all keyspaces / shards to have healthy tablets of types [PRIMARY REPLICA], may be in degraded mode
E0528 20:57:33.316522   60966 vtgate.go:636] Execute: table t9 not found, request: map[BindVariables:map[] Session:autocommit:true options:{included_fields:ALL workload:OLTP planner_version:Gen4CompareV3} row_count:-1 DDLStrategy:"direct" SessionUUID:"f0c9ca36-fdd4-11ed-b22e-aa0e14275aa9" enable_system_settings:true Sql:delete from t9]
E0528 20:57:33.350183   60966 server.go:348] mysql_server caught panic:
runtime error: slice bounds out of range [:3] with capacity 2
runtime/panic.go:139 (0x1049f534b)
vitess.io/vitess/go/sqltypes/result.go:161 (0x1056d101f)
vitess.io/vitess/go/vt/vtgate/engine/ordered_aggregate.go:176 (0x1056d0d68)
vitess.io/vitess/go/vt/vtgate/vcursor_impl.go:437 (0x1057cb9db)
vitess.io/vitess/go/vt/vtgate/plan_execute.go:217 (0x1057b094b)
vitess.io/vitess/go/vt/vtgate/executor.go:390 (0x1057a6d4b)
vitess.io/vitess/go/vt/vtgate/plan_execute.go:109 (0x1057b0227)
vitess.io/vitess/go/vt/vtgate/executor.go:388 (0x1057a6bcb)
vitess.io/vitess/go/vt/vtgate/executor.go:201 (0x1057a546f)
vitess.io/vitess/go/vt/vtgate/vtgate.go:456 (0x1057d9ed3)
vitess.io/vitess/go/vt/vtgate/plugin_mysql_server.go:243 (0x1057b266f)
vitess.io/vitess/go/mysql/conn.go:1359 (0x1054006b7)
vitess.io/vitess/go/mysql/conn.go:1344 (0x105400377)
vitess.io/vitess/go/mysql/conn.go:910 (0x1053fceb3)
vitess.io/vitess/go/mysql/server.go:527 (0x10541a8cb)
vitess.io/vitess/go/mysql/server.go:331 (0x105419897)
runtime/asm_arm64.s:1172 (0x104a2e863)
W0528 20:57:36.462962   60966 tablet_health_check.go:334] tablet alias:{cell:"test_aggr" uid:5557} hostname:"localhost" port_map:{key:"grpc" value:12711} port_map:{key:"vt" value:12710} keyspace:"ks_aggr" shard:"80-" key_range:{start:"\x80"} type:PRIMARY mysql_hostname:"localhost" mysql_port:12712 primary_term_start_time:{seconds:1685332619 nanoseconds:317212000} default_conn_collation:255 healthcheck stream error: Code: CANCELED
vttablet: rpc error: code = Canceled desc = context canceled
W0528 20:57:36.462946   60966 tablet_health_check.go:334] tablet alias:{cell:"test_aggr" uid:5556} hostname:"localhost" port_map:{key:"grpc" value:12708} port_map:{key:"vt" value:12707} keyspace:"ks_aggr" shard:"-80" key_range:{end:"\x80"} type:PRIMARY mysql_hostname:"localhost" mysql_port:12709 primary_term_start_time:{seconds:1685332615 nanoseconds:769608000} default_conn_collation:255 healthcheck stream error: Code: CANCELED
vttablet: rpc error: code = Canceled desc = context canceled
arvind-murty commented 1 year ago

Possibly related to Issue #13179.