Skip to content

Commit

Permalink
importinto: fix panic when import to a temporary table, disallow impo…
Browse files Browse the repository at this point in the history
…rt to cached table (#55983)

close #55970
  • Loading branch information
D3Hunter authored Sep 14, 2024
1 parent b1767ca commit ae86e04
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/planner/core/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4470,6 +4470,11 @@ func (b *PlanBuilder) buildImportInto(ctx context.Context, ld *ast.ImportIntoStm
}

tnW := b.resolveCtx.GetTableName(ld.Table)
if tnW.TableInfo.TempTableType != model.TempTableNone {
return nil, errors.Errorf("IMPORT INTO does not support temporary table")
} else if tnW.TableInfo.TableCacheStatusType != model.TableCacheStatusDisable {
return nil, errors.Errorf("IMPORT INTO does not support cached table")
}
p := ImportInto{
Path: ld.Path,
Format: ld.Format,
Expand Down
13 changes: 13 additions & 0 deletions tests/integrationtest/r/executor/import_into.result
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,16 @@ import into t from '';
Error 8156 (HY000): The value of INFILE must not be empty when LOAD DATA from LOCAL
import into t from '/a.csv' format 'xx';
Error 8157 (HY000): The FORMAT 'xx' is not supported
drop table if exists temp;
create temporary table temp (id int);
import into temp from '/file.csv';
Error 1105 (HY000): IMPORT INTO does not support temporary table
drop table if exists gtemp;
create global temporary table gtemp (id int) on commit delete rows;
import into gtemp from '/file.csv';
Error 1105 (HY000): IMPORT INTO does not support temporary table
drop table if exists cachetbl;
create table cachetbl (id int);
alter table cachetbl cache;
import into cachetbl from '/file.csv';
Error 1105 (HY000): IMPORT INTO does not support cached table
16 changes: 16 additions & 0 deletions tests/integrationtest/t/executor/import_into.test
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,19 @@ import into t from '';
-- error 8157
import into t from '/a.csv' format 'xx';

# import into temporary or cached table is not supported
drop table if exists temp;
create temporary table temp (id int);
-- error 1105
import into temp from '/file.csv';

drop table if exists gtemp;
create global temporary table gtemp (id int) on commit delete rows;
-- error 1105
import into gtemp from '/file.csv';

drop table if exists cachetbl;
create table cachetbl (id int);
alter table cachetbl cache;
-- error 1105
import into cachetbl from '/file.csv';

0 comments on commit ae86e04

Please sign in to comment.