Skip to content

Commit

Permalink
Merge pull request #3329 from tinyspeck/vtexplain-fix-floats
Browse files Browse the repository at this point in the history
vtexplain fix float columns
  • Loading branch information
sougou authored Oct 19, 2017
2 parents 02577d4 + 67cf5ff commit 767e9e8
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 28 deletions.
3 changes: 2 additions & 1 deletion data/test/vtexplain/test-schema.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
create table t1 (
id bigint(20) unsigned not null,
val bigint(20) unsigned not null default 0,
intval bigint(20) unsigned not null default 0,
floatval float not null default 0,
primary key (id)
);

Expand Down
85 changes: 68 additions & 17 deletions data/test/vtexplain/unsharded-output.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@
}
},
{
"SQL": "insert into t1 (id,val) values (1,2)",
"SQL": "insert into t1 (id,intval,floatval) values (1,2,3.14)",
"Plans": [
{
"Original": "insert into t1(id, val) values (:vtg1, :vtg2)",
"Original": "insert into t1(id, intval, floatval) values (:vtg1, :vtg2, :vtg3)",
"Instructions": {
"Opcode": "InsertUnsharded",
"Keyspace": {
"Name": "ks_unsharded",
"Sharded": false
},
"Query": "insert into t1(id, val) values (:vtg1, :vtg2)",
"Query": "insert into t1(id, intval, floatval) values (:vtg1, :vtg2, :vtg3)",
"Table": "t1"
}
}
Expand All @@ -56,11 +56,12 @@
"TabletQueries": [
{
"Time": 1,
"SQL": "insert into t1(id, val) values (:vtg1, :vtg2)",
"SQL": "insert into t1(id, intval, floatval) values (:vtg1, :vtg2, :vtg3)",
"BindVars": {
"#maxLimit": "10001",
"vtg1": "1",
"vtg2": "2"
"vtg2": "2",
"vtg3": "3.14"
}
}
],
Expand All @@ -71,7 +72,7 @@
},
{
"Time": 1,
"SQL": "insert into t1(id, val) values (1, 2)"
"SQL": "insert into t1(id, intval, floatval) values (1, 2, 3.14)"
},
{
"Time": 2,
Expand All @@ -82,17 +83,17 @@
}
},
{
"SQL": "update t1 set val = 10",
"SQL": "update t1 set intval = 10",
"Plans": [
{
"Original": "update t1 set val = :vtg1",
"Original": "update t1 set intval = :vtg1",
"Instructions": {
"Opcode": "UpdateUnsharded",
"Keyspace": {
"Name": "ks_unsharded",
"Sharded": false
},
"Query": "update t1 set val = :vtg1"
"Query": "update t1 set intval = :vtg1"
}
}
],
Expand All @@ -101,7 +102,7 @@
"TabletQueries": [
{
"Time": 1,
"SQL": "update t1 set val = :vtg1",
"SQL": "update t1 set intval = :vtg1",
"BindVars": {
"#maxLimit": "10001",
"vtg1": "10"
Expand All @@ -119,7 +120,55 @@
},
{
"Time": 1,
"SQL": "update t1 set val = 10 where id in (1)"
"SQL": "update t1 set intval = 10 where id in (1)"
},
{
"Time": 2,
"SQL": "commit"
}
]
}
}
},
{
"SQL": "update t1 set floatval = 9.99",
"Plans": [
{
"Original": "update t1 set floatval = :vtg1",
"Instructions": {
"Opcode": "UpdateUnsharded",
"Keyspace": {
"Name": "ks_unsharded",
"Sharded": false
},
"Query": "update t1 set floatval = :vtg1"
}
}
],
"TabletActions": {
"ks_unsharded/-": {
"TabletQueries": [
{
"Time": 1,
"SQL": "update t1 set floatval = :vtg1",
"BindVars": {
"#maxLimit": "10001",
"vtg1": "9.99"
}
}
],
"MysqlQueries": [
{
"Time": 1,
"SQL": "begin"
},
{
"Time": 1,
"SQL": "select id from t1 limit 10001 for update"
},
{
"Time": 1,
"SQL": "update t1 set floatval = 9.99 where id in (1)"
},
{
"Time": 2,
Expand Down Expand Up @@ -174,17 +223,17 @@
}
},
{
"SQL": "insert into t1 (id,val) values (1,2) on duplicate key update val=3",
"SQL": "insert into t1 (id,intval,floatval) values (1,2,3.14) on duplicate key update intval=3, floatval=3.14",
"Plans": [
{
"Original": "insert into t1(id, val) values (:vtg1, :vtg2) on duplicate key update val = :vtg3",
"Original": "insert into t1(id, intval, floatval) values (:vtg1, :vtg2, :vtg3) on duplicate key update intval = :vtg4, floatval = :vtg5",
"Instructions": {
"Opcode": "InsertUnsharded",
"Keyspace": {
"Name": "ks_unsharded",
"Sharded": false
},
"Query": "insert into t1(id, val) values (:vtg1, :vtg2) on duplicate key update val = :vtg3",
"Query": "insert into t1(id, intval, floatval) values (:vtg1, :vtg2, :vtg3) on duplicate key update intval = :vtg4, floatval = :vtg5",
"Table": "t1"
}
}
Expand All @@ -194,12 +243,14 @@
"TabletQueries": [
{
"Time": 1,
"SQL": "insert into t1(id, val) values (:vtg1, :vtg2) on duplicate key update val = :vtg3",
"SQL": "insert into t1(id, intval, floatval) values (:vtg1, :vtg2, :vtg3) on duplicate key update intval = :vtg4, floatval = :vtg5",
"BindVars": {
"#maxLimit": "10001",
"vtg1": "1",
"vtg2": "2",
"vtg3": "3"
"vtg3": "3.14",
"vtg4": "3",
"vtg5": "3.14"
}
}
],
Expand All @@ -210,7 +261,7 @@
},
{
"Time": 1,
"SQL": "insert into t1(id, val) values (1, 2) on duplicate key update val = 3"
"SQL": "insert into t1(id, intval, floatval) values (1, 2, 3.14) on duplicate key update intval = 3, floatval = 3.14"
},
{
"Time": 2,
Expand Down
20 changes: 14 additions & 6 deletions data/test/vtexplain/unsharded-output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,26 @@ select * from t1
1 ks_unsharded/-: select * from t1 limit 10001

----------------------------------------------------------------------
insert into t1 (id,val) values (1,2)
insert into t1 (id,intval,floatval) values (1,2,3.14)

1 ks_unsharded/-: begin
1 ks_unsharded/-: insert into t1(id, val) values (1, 2)
1 ks_unsharded/-: insert into t1(id, intval, floatval) values (1, 2, 3.14)
2 ks_unsharded/-: commit

----------------------------------------------------------------------
update t1 set val = 10
update t1 set intval = 10

1 ks_unsharded/-: begin
1 ks_unsharded/-: select id from t1 limit 10001 for update
1 ks_unsharded/-: update t1 set val = 10 where id in (1)
1 ks_unsharded/-: update t1 set intval = 10 where id in (1)
2 ks_unsharded/-: commit

----------------------------------------------------------------------
update t1 set floatval = 9.99

1 ks_unsharded/-: begin
1 ks_unsharded/-: select id from t1 limit 10001 for update
1 ks_unsharded/-: update t1 set floatval = 9.99 where id in (1)
2 ks_unsharded/-: commit

----------------------------------------------------------------------
Expand All @@ -26,10 +34,10 @@ delete from t1 where id = 100
2 ks_unsharded/-: commit

----------------------------------------------------------------------
insert into t1 (id,val) values (1,2) on duplicate key update val=3
insert into t1 (id,intval,floatval) values (1,2,3.14) on duplicate key update intval=3, floatval=3.14

1 ks_unsharded/-: begin
1 ks_unsharded/-: insert into t1(id, val) values (1, 2) on duplicate key update val = 3
1 ks_unsharded/-: insert into t1(id, intval, floatval) values (1, 2, 3.14) on duplicate key update intval = 3, floatval = 3.14
2 ks_unsharded/-: commit

----------------------------------------------------------------------
7 changes: 4 additions & 3 deletions data/test/vtexplain/unsharded-queries.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
select * from t1;
insert into t1 (id,val) values (1,2);
update t1 set val = 10;
insert into t1 (id,intval,floatval) values (1,2,3.14);
update t1 set intval = 10;
update t1 set floatval = 9.99;
delete from t1 where id = 100;
insert into t1 (id,val) values (1,2) on duplicate key update val=3;
insert into t1 (id,intval,floatval) values (1,2,3.14) on duplicate key update intval=3, floatval=3.14;
2 changes: 1 addition & 1 deletion go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ func (ct *ColumnType) SQLType() querypb.Type {
return sqltypes.Timestamp
case keywordStrings[YEAR]:
return sqltypes.Year
case keywordStrings[FLOAT]:
case keywordStrings[FLOAT_TYPE]:
return sqltypes.Float32
case keywordStrings[DOUBLE]:
return sqltypes.Float64
Expand Down

0 comments on commit 767e9e8

Please sign in to comment.