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

panic when insert values with a valid column plus somethings #4482

Closed
winkyao opened this issue Sep 8, 2017 · 3 comments
Closed

panic when insert values with a valid column plus somethings #4482

winkyao opened this issue Sep 8, 2017 · 3 comments
Assignees
Labels
type/bug This issue is a bug.

Comments

@winkyao
Copy link
Contributor

winkyao commented Sep 8, 2017

MySQL:

mysql> create table t1 (a int not null);
Query OK, 0 rows affected (0.01 sec)

mysql> insert into t1 values (a+2);
Query OK, 1 row affected (0.00 sec)

mysql> select * from t1;
+---+
| a |
+---+
| 2 |
+---+
1 row in set (0.00 sec)

TiDB:

mysql> create table t1 (a int not null);
Query OK, 0 rows affected (0.07 sec)

mysql> insert into t1 values (a+2);
ERROR 2013 (HY000): Lost connection to MySQL server during query

panic with logs:

2017/09/08 23:30:25.637 conn.go:387: [error] lastCmd insert into t1 values (a+2), runtime error: invalid memory address or nil pointer dereference, goroutine 593 [running]:
github.com/pingcap/tidb/server.(*clientConn).Run.func1(0xc42026f3f0)
  /home/wink/machome/go_dir/src/github.com/pingcap/tidb/server/conn.go:385 +0xcd
panic(0x109aca0, 0x1cba290)
  /usr/local/go/src/runtime/panic.go:489 +0x2cf
github.com/pingcap/tidb/expression.(*Schema).FindColumnAndIndex(0x0, 0xc42081b2d0, 0x0, 0xc420246c00, 0xc4208f9800, 0x0)
  /home/wink/machome/go_dir/src/github.com/pingcap/tidb/expression/schema.go:111 +0x7b
github.com/pingcap/tidb/expression.(*Schema).FindColumn(0x0, 0xc42081b2d0, 0x0, 0x450bf7, 0xc4209d3320)
  /home/wink/machome/go_dir/src/github.com/pingcap/tidb/expression/schema.go:102 +0x35
github.com/pingcap/tidb/plan.(*expressionRewriter).toColumn(0xc42081b3b0, 0xc42081b2d0)
  /home/wink/machome/go_dir/src/github.com/pingcap/tidb/plan/expression_rewriter.go:1120 +0x51
github.com/pingcap/tidb/plan.(*expressionRewriter).Leave(0xc42081b3b0, 0x1994660, 0xc42081b2d0, 0x1994660, 0xc42081b2d0, 0xc420850f00)
  /home/wink/machome/go_dir/src/github.com/pingcap/tidb/plan/expression_rewriter.go:694 +0xa68
github.com/pingcap/tidb/ast.(*ColumnName).Accept(0xc42081b2d0, 0x198cba0, 0xc42081b3b0, 0x19946a0, 0xc4207b5500, 0x0)
  /home/wink/machome/go_dir/src/github.com/pingcap/tidb/ast/expressions.go:345 +0x9c
github.com/pingcap/tidb/ast.(*ColumnNameExpr).Accept(0xc4207b5500, 0x198cba0, 0xc42081b3b0, 0x1994520, 0xc4207e0820, 0x0)
  /home/wink/machome/go_dir/src/github.com/pingcap/tidb/ast/expressions.go:367 +0xa8
github.com/pingcap/tidb/ast.(*BinaryOperationExpr).Accept(0xc4207e0820, 0x198cba0, 0xc42081b3b0, 0x10, 0x1169800, 0xc4208a9898)
  /home/wink/machome/go_dir/src/github.com/pingcap/tidb/ast/expressions.go:151 +0xb0
github.com/pingcap/tidb/plan.(*planBuilder).rewriteWithPreprocess(0xc4207b55c0, 0x199e660, 0xc4207e0820, 0x0, 0x0, 0x0, 0x1, 0x0, 0xc420851501, 0xc4207b1950, ...)
  /home/wink/machome/go_dir/src/github.com/pingcap/tidb/plan/expression_rewriter.go:84 +0x120
github.com/pingcap/tidb/plan.(*planBuilder).rewrite(0xc4207b55c0, 0x199e660, 0xc4207e0820, 0x0, 0x0, 0x0, 0x1, 0x1, 0xc4207b18c0, 0x1, ...)
  /home/wink/machome/go_dir/src/github.com/pingcap/tidb/plan/expression_rewriter.go:65 +0x88
github.com/pingcap/tidb/plan.(*planBuilder).buildInsert(0xc4207b55c0, 0xc420774960, 0x500d82e1, 0xc4208275f0)
  /home/wink/machome/go_dir/src/github.com/pingcap/tidb/plan/planbuilder.go:746 +0xbfb
github.com/pingcap/tidb/plan.(*planBuilder).build(0xc4207b55c0, 0x1994ea0, 0xc420774960, 0x0, 0xc4208275f0)
  /home/wink/machome/go_dir/src/github.com/pingcap/tidb/plan/planbuilder.go:150 +0x2e9
github.com/pingcap/tidb/plan.Optimize(0x199f240, 0xc42026f600, 0x1994ea0, 0xc420774960, 0x7f960889bcb8, 0xc4209e3020, 0x0, 0x0, 0x1cd0020, 0x7f96088ea000)
  /home/wink/machome/go_dir/src/github.com/pingcap/tidb/plan/optimizer.go:71 +0x1a7
github.com/pingcap/tidb/executor.(*Compiler).Compile(0xc4208518f0, 0x199f240, 0xc42026f600, 0x7f960889c2a0, 0xc420774960, 0xc4208518f0, 0x4867d2, 0xc420697500, 0xc4207e7db0)
  /home/wink/machome/go_dir/src/github.com/pingcap/tidb/executor/compiler.go:41 +0x1b7
github.com/pingcap/tidb.Compile(0x199f240, 0xc42026f600, 0x7f960889c2a0, 0xc420774960, 0x4, 0x121f7e8, 0xf, 0xc4200128c0)
  /home/wink/machome/go_dir/src/github.com/pingcap/tidb/tidb.go:150 +0x57
github.com/pingcap/tidb.(*session).Execute(0xc42026f600, 0xc420816201, 0x1b, 0xc420851bb8, 0x410aac, 0xc420851bb8, 0x411082, 0xc420642040)
  /home/wink/machome/go_dir/src/github.com/pingcap/tidb/session.go:667 +0x518
github.com/pingcap/tidb/server.(*TiDBContext).Execute(0xc420276390, 0xc420816201, 0x1b, 0x0, 0x0, 0xc420851c88, 0x470658, 0xc4206888f8)
  /home/wink/machome/go_dir/src/github.com/pingcap/tidb/server/driver_tidb.go:194 +0x62
github.com/pingcap/tidb/server.(*clientConn).handleQuery(0xc42026f3f0, 0xc420816201, 0x1b, 0x0, 0x0)
  /home/wink/machome/go_dir/src/github.com/pingcap/tidb/server/conn.go:727 +0x8d
github.com/pingcap/tidb/server.(*clientConn).dispatch(0xc42026f3f0, 0xc420816201, 0x1c, 0x1b, 0x0, 0x0)
  /home/wink/machome/go_dir/src/github.com/pingcap/tidb/server/conn.go:516 +0x42e
@winkyao winkyao added the type/bug This issue is a bug. label Sep 8, 2017
@winoros
Copy link
Member

winoros commented Sep 8, 2017

It seems that mysql treat the column in values() as NULL value. So we do a expression rewrite in executor build phase?

mysql> create table t(a int);
Query OK, 0 rows affected (0.00 sec)

mysql> insert into t values(a);
Query OK, 1 row affected (0.01 sec)

mysql> select * from t;
+------+
| a    |
+------+
| NULL |
+------+
1 row in set (0.00 sec)
mysql> create table t(a enum('a', 'b'));
Query OK, 0 rows affected (0.01 sec)

mysql> insert into t values(a);
Query OK, 1 row affected (0.00 sec)

mysql> select * from t;
+------+
| a    |
+------+
| NULL |
+------+
1 row in set (0.00 sec)
mysql> create table t(a blob);
Query OK, 0 rows affected (0.01 sec)

mysql> insert into t values(a);
Query OK, 1 row affected (0.00 sec)

mysql> select * from t;
+------+
| a    |
+------+
| NULL |
+------+
1 row in set (0.00 sec)
mysql> create table t(a int, b int);
Query OK, 0 rows affected (0.00 sec)

mysql> insert into t values(a*b, b*b);
Query OK, 1 row affected (0.00 sec)

mysql> select * from t;
+------+------+
| a    | b    |
+------+------+
| NULL | NULL |
+------+------+
1 row in set (0.00 sec)

@winkyao
Copy link
Contributor Author

winkyao commented Sep 9, 2017

@winoros if the column has not null flag, MySQL will treat it as zero value:

mysql> create table t1 (a int not null);
Query OK, 0 rows affected (0.01 sec)

mysql> insert into t1 values(a);
Query OK, 1 row affected (0.01 sec)

mysql> select * from t1;
+---+
| a |
+---+
| 0 |
+---+
1 row in set (0.00 sec)

@winoros winoros self-assigned this Sep 11, 2017
@XuHuaiyu
Copy link
Contributor

In MySQL:

drop table if exists t;
create table t (a bigint not null, b bigint not null);
insert into t value(b + 1, a);
insert into t set a = b + a, b = a + 1;
insert into t value(sysdate(), a);
select * from t;

+----------------+----------------+
| a              | b              |
+----------------+----------------+
|              1 |              1 |
|              0 |              1 |
| 20170913183817 | 20170913183817 |
+----------------+----------------+
3 rows in set (0.00 sec)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug This issue is a bug.
Projects
None yet
Development

No branches or pull requests

3 participants