Skip to content
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

Wrong column value can be inserted due to parameterization variable confusion #6266

Closed
aquarapid opened this issue Jun 4, 2020 · 0 comments
Milestone

Comments

@aquarapid
Copy link
Contributor

Scenario:

  • From master (19fdf8b), start up the local sharded examples:
$ cd examples/local/
$ for i in `ls -1 *.sh | grep ^[1-3]` ; do echo $i ; ./$i ; sleep 5 ; done

Now, have the following vschema and schema:

vschema.json:

{
    "sharded": true,
    "vindexes": {
        "hash": {
            "type": "hash"
        },
        "lookup1": {
            "type": "consistent_lookup",
            "params": {
                "table": "lookup1",
                "from": "field",
                "to": "keyspace_id",
		"ignore_nulls": "true"
            },
            "owner": "t1"
        },
        "lookup2": {
            "type": "consistent_lookup",
            "params": {
                "table": "lookup2",
                "from": "field2",
                "to": "keyspace_id",
		"ignore_nulls": "true"
            },
            "owner": "t1"
        }
    },
    "tables": {
        "t1": {
            "column_vindexes": [
                {
                    "column": "id",
                    "name": "hash"
                },
                {
                    "column": "field",
                    "name": "lookup1"
                },
                {
                    "column": "field2",
                    "name": "lookup2"
                }
            ]
        },
        "lookup1": {
            "column_vindexes": [
                {
                    "column": "field",
                    "name": "hash"
                }
            ]
        },
        "lookup2": {
            "column_vindexes": [
                {
                    "column": "field2",
                    "name": "hash"
                }
            ]
        }
    }
}

schema.sql:

CREATE TABLE t1 (
    id BIGINT NOT NULL,
    field BIGINT NOT NULL,
    field2 BIGINT,
    PRIMARY KEY (id)
) ENGINE=Innodb;


CREATE TABLE lookup1 (
    field BIGINT NOT NULL,
    keyspace_id binary(8),
    UNIQUE KEY (field)
) ENGINE=Innodb;

CREATE TABLE lookup2 (
    field2 BIGINT NOT NULL,
    keyspace_id binary(8),
    UNIQUE KEY (field2)
) ENGINE=Innodb;

Apply the sharded vschema and schema on the sharded customer keyspace in the examples:

$ vtctlclient -server localhost:15999 ApplyVSchema -vschema_file=`pwd`/vschema.json customer
$ vtctlclient -server localhost:15999 ApplySchema -sql-file=`pwd`/schema.sql customer

Now, connect to vtgate, and run the given multi-value insert:

$ mysql -s -u root -P 15306 -h 127.0.0.1 customer
mysql> INSERT INTO t1 (id, field, field2) VALUES (0,1,2), (1,2,3), (2,3,4), (3,4,5), (4,5,6), (5,6,7), (6,7,8), (7,8,9), (8,9,10), (9,10,11), (10,11,12), (11,12,13), (12,13,14), (13,14,15), (14,15,16), (15,16,17), (16,17,18), (17,18,19), (18,19,20), (19,20,21), (20,21,22);

This all works fine, but now inspect the result of the insert:

mysql> select id, field, field2 from t1 order by id;
id	field	field2
0	1	2
1	2	3
2	3	4
3	4	5
4	5	6
5	6	7
6	7	8
7	8	9
8	9	10
9	10	11
10	11	12
11	12	13
12	13	14
13	14	15
14	15	16
15	16	17
16	17	18
17	18	19
18	19	20
19	20	21
20	2	22

As can be seen, the value for t1.field for id = 20 is incorrect, it should be 21, not 2.

@systay systay closed this as completed in e65e5e8 Jun 5, 2020
gedgar pushed a commit to planetscale/vitess that referenced this issue Jun 9, 2020
Signed-off-by: Andres Taylor <andres@planetscale.com>
@deepthi deepthi added this to the v7.0 milestone Jun 15, 2020
systay added a commit to planetscale/vitess that referenced this issue Jun 16, 2020
Signed-off-by: Andres Taylor <andres@planetscale.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants