Skip to content

Commit

Permalink
prevent index creation on attach table
Browse files Browse the repository at this point in the history
  • Loading branch information
dantengsky committed Aug 1, 2024
1 parent dc5f201 commit 3827ecc
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/query/sql/src/planner/binder/ddl/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,13 @@ impl Binder {
let table_entry = &tables[0];
let table = table_entry.table();

if table.is_read_only() {
return Err(ErrorCode::UnsupportedIndex(format!(
"Table {} is read-only, creating index not allowed",
table.name()
)));
}

if !table.support_index() {
return Err(ErrorCode::UnsupportedIndex(format!(
"Table engine {} does not support create index",
Expand Down Expand Up @@ -416,6 +423,14 @@ impl Binder {
self.normalize_object_identifier_triple(catalog, database, table);

let table = self.ctx.get_table(&catalog, &database, &table).await?;

if table.is_read_only() {
return Err(ErrorCode::UnsupportedIndex(format!(
"Table {} is read-only, creating inverted index not allowed",
table.name()
)));
}

if !table.support_index() {
return Err(ErrorCode::UnsupportedIndex(format!(
"Table engine {} does not support create inverted index",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
1
2
<<<<
#### select attach table from system.tables
>>>> select is_attach from system.tables where name = 'table_to';
ATTACH
<<<<
#### select attach table with self-defined connection
>>>> select * from table_to2 order by a;
0
Expand Down
3 changes: 3 additions & 0 deletions tests/suites/5_ee/04_attach_read_only/02_0004_attach_table.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ echo "attach table table_to2 's3://testbucket/admin/data/$storage_prefix' connec
comment "select attach table"
query "select * from table_to order by a;"

comment "select attach table from system.tables"
query "select is_attach from system.tables where name = 'table_to';"

comment "select attach table with self-defined connection"
query "select * from table_to2 order by a;"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
create index should fail
Error: APIError: ResponseError with 1601: Table test_json_read_only is read-only, creating inverted index not allowed
create virtual column should fail
Error: APIError: ResponseError with 3905: Modification not permitted: Table 'test_json_read_only' is READ ONLY, preventing any changes or updates.
alter virtual column should fail
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
. "$CURDIR"/../../../shell_env.sh

echo "create database if not exists test_attach_only;" | $BENDSQL_CLIENT_CONNECT
echo "create or replace database test_attach_only;" | $BENDSQL_CLIENT_CONNECT

# mutation related enterprise features

echo "create table test_attach_only.test_json(id int, val json) 's3://testbucket/admin/data/' connection=(access_key_id ='minioadmin' secret_access_key ='minioadmin' endpoint_url='${STORAGE_S3_ENDPOINT_URL}');" | $BENDSQL_CLIENT_CONNECT
echo "create or replace table test_attach_only.test_json(id int, val json) 's3://testbucket/admin/data/' connection=(access_key_id ='minioadmin' secret_access_key ='minioadmin' endpoint_url='${STORAGE_S3_ENDPOINT_URL}');" | $BENDSQL_CLIENT_CONNECT
echo "insert into test_attach_only.test_json values(1, '{\"a\":33,\"b\":44}'),(2, '{\"a\":55,\"b\":66}')" | $BENDSQL_CLIENT_CONNECT
storage_prefix=$(mysql -uroot -h127.0.0.1 -P3307 -e "set global hide_options_in_show_create_table=0;show create table test_attach_only.test_json" | grep -i snapshot_location | awk -F'SNAPSHOT_LOCATION='"'"'|_ss' '{print $2}')
echo "attach table test_attach_only.test_json_read_only 's3://testbucket/admin/data/$storage_prefix' connection=(access_key_id ='minioadmin' secret_access_key ='minioadmin' endpoint_url='${STORAGE_S3_ENDPOINT_URL}');" | $BENDSQL_CLIENT_CONNECT


echo "create index should fail"
echo "CREATE INVERTED INDEX IF NOT EXISTS idx1 ON test_attach_only.test_json_read_only(val)" | $BENDSQL_CLIENT_CONNECT

echo "create virtual column should fail"
echo "CREATE VIRTUAL COLUMN (val['a'], val['b']) FOR test_attach_only.test_json_read_only" | $BENDSQL_CLIENT_CONNECT

Expand Down

0 comments on commit 3827ecc

Please sign in to comment.