From d2f4e1b2ad92ea1ec7f62765d158a278e376ab5b Mon Sep 17 00:00:00 2001 From: Null not nil <67764674+nullnotnil@users.noreply.github.com> Date: Thu, 10 Dec 2020 00:18:21 -0700 Subject: [PATCH 1/2] cherry pick #20924 to release-4.0 Signed-off-by: ti-srebot --- server/conn.go | 4 +++- server/server_test.go | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/server/conn.go b/server/conn.go index 55d3a14707f2c..efb203b8ec294 100644 --- a/server/conn.go +++ b/server/conn.go @@ -1251,7 +1251,9 @@ func (cc *clientConn) handleLoadData(ctx context.Context, loadDataInfo *executor if loadDataInfo == nil { return errors.New("load data info is empty") } - + if !loadDataInfo.Table.Meta().IsBaseTable() { + return errors.New("can only load data into base tables") + } err := cc.writeReq(ctx, loadDataInfo.Path) if err != nil { return err diff --git a/server/server_test.go b/server/server_test.go index c78f08e238f2c..abd008dd862ac 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -533,6 +533,17 @@ func (cli *testServerClient) runTestLoadData(c *C, server *Server) { }, "LoadData", func(dbt *DBTest) { dbt.mustExec("set @@tidb_dml_batch_size = 3") dbt.mustExec("create table test (a varchar(255), b varchar(255) default 'default value', c int not null auto_increment, primary key(c))") + dbt.mustExec("create view v1 as select 1") + dbt.mustExec("create sequence s1") + + // can't insert into views (in TiDB) or sequences. issue #20880 + _, err = dbt.db.Exec("load data local infile '/tmp/load_data_test.csv' into table v1") + dbt.Assert(err, NotNil) + dbt.Assert(err.Error(), Equals, "Error 1105: can only load data into base tables") + _, err = dbt.db.Exec("load data local infile '/tmp/load_data_test.csv' into table s1") + dbt.Assert(err, NotNil) + dbt.Assert(err.Error(), Equals, "Error 1105: can only load data into base tables") + rs, err1 := dbt.db.Exec("load data local infile '/tmp/load_data_test.csv' into table test") dbt.Assert(err1, IsNil) lastID, err1 := rs.LastInsertId() From 05ca7f6158b93230ec5bc711624c271f2ff6727e Mon Sep 17 00:00:00 2001 From: Null not nil <67764674+nullnotnil@users.noreply.github.com> Date: Thu, 10 Dec 2020 18:10:59 -0700 Subject: [PATCH 2/2] Update conn.go --- server/conn.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/conn.go b/server/conn.go index efb203b8ec294..8f3fe613c733b 100644 --- a/server/conn.go +++ b/server/conn.go @@ -1251,7 +1251,7 @@ func (cc *clientConn) handleLoadData(ctx context.Context, loadDataInfo *executor if loadDataInfo == nil { return errors.New("load data info is empty") } - if !loadDataInfo.Table.Meta().IsBaseTable() { + if loadDataInfo.Table.Meta().IsView() || loadDataInfo.Table.Meta().IsSequence() { return errors.New("can only load data into base tables") } err := cc.writeReq(ctx, loadDataInfo.Path)