From c2e5111ad3530e8b1933e97a2d5bd3d146bb23d2 Mon Sep 17 00:00:00 2001 From: yinyj17 Date: Wed, 27 Mar 2024 08:51:17 +0000 Subject: [PATCH] fix encryption related views are invalid with ONLY_FULL_GROUP_BY --- src/share/inner_table/ob_inner_table_schema.21101_21150.cpp | 4 ++-- src/share/inner_table/ob_inner_table_schema_def.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/share/inner_table/ob_inner_table_schema.21101_21150.cpp b/src/share/inner_table/ob_inner_table_schema.21101_21150.cpp index dece498f4a..4d8ea786e3 100644 --- a/src/share/inner_table/ob_inner_table_schema.21101_21150.cpp +++ b/src/share/inner_table/ob_inner_table_schema.21101_21150.cpp @@ -510,7 +510,7 @@ int ObInnerTableSchema::v_ob_encrypted_tables_schema(ObTableSchema &table_schema table_schema.set_collation_type(ObCharset::get_default_collation(ObCharset::get_default_charset())); if (OB_SUCC(ret)) { - if (OB_FAIL(table_schema.set_view_definition(R"__( SELECT A.table_id AS TABLE_ID, A.table_name AS TABLE_NAME, B.tablespace_id AS TABLESPACE_ID, B.encryption_name AS ENCRYPTIONALG, CASE WHEN B.encryption_name != '' AND sum(encrypted_macro_block_count) = sum(macro_block_count) THEN 'YES' ELSE 'NO' END AS ENCRYPTED, hex(B.encrypt_key) AS ENCRYPTEDKEY, B.master_key_id AS MASTERKEYID, sum(encrypted_macro_block_count) AS BLOCKS_ENCRYPTED, (sum(macro_block_count) - sum(encrypted_macro_block_count)) AS BLOCKS_DECRYPTED, CASE WHEN (B.encryption_name != '' AND sum(encrypted_macro_block_count) < sum(macro_block_count)) THEN 'ENCRYPTING' WHEN (B.encryption_name = '' AND sum(encrypted_macro_block_count) > 0) THEN 'DECRYPTING' ELSE 'NORMAL' END AS STATUS, A.tenant_id as CON_ID FROM (SELECT T.tenant_id, T.table_id, T.table_name, T.table_type, T.tablespace_id, T.tablet_id FROM oceanbase.__all_table T where T.part_level = 0 and T.table_mode >> 12 & 15 in (0,1) UNION ALL SELECT T.tenant_id, T.table_id, T.table_name, T.table_type, T.tablespace_id, P.tablet_id FROM oceanbase.__all_table T, oceanbase.__all_part P WHERE T.part_level = 1 and T.tenant_id = P.tenant_id and T.table_id = P.table_id UNION ALL SELECT T.tenant_id, T.table_id, T.table_name, T.table_type, T.tablespace_id, SP.tablet_id FROM oceanbase.__all_table T, oceanbase.__all_sub_part SP WHERE T.part_level = 2 and T.tenant_id = SP.tenant_id and T.table_id = SP.table_id ) A JOIN oceanbase.__all_tenant_tablespace B ON A.tenant_id = B.tenant_id AND A.tablespace_id = B.tablespace_id JOIN oceanbase.__all_virtual_tablet_encrypt_info E ON E.tenant_id = effective_tenant_id() and E.tablet_id = A.tablet_id WHERE A.tenant_id = 0 AND A.table_type != 12 AND A.table_type != 13 GROUP BY A.tenant_id, A.table_id )__"))) { + if (OB_FAIL(table_schema.set_view_definition(R"__( SELECT A.table_id AS TABLE_ID, A.table_name AS TABLE_NAME, B.tablespace_id AS TABLESPACE_ID, B.encryption_name AS ENCRYPTIONALG, CASE WHEN B.encryption_name != '' AND sum(encrypted_macro_block_count) = sum(macro_block_count) THEN 'YES' ELSE 'NO' END AS ENCRYPTED, hex(B.encrypt_key) AS ENCRYPTEDKEY, B.master_key_id AS MASTERKEYID, sum(encrypted_macro_block_count) AS BLOCKS_ENCRYPTED, (sum(macro_block_count) - sum(encrypted_macro_block_count)) AS BLOCKS_DECRYPTED, CASE WHEN (B.encryption_name != '' AND sum(encrypted_macro_block_count) < sum(macro_block_count)) THEN 'ENCRYPTING' WHEN (B.encryption_name = '' AND sum(encrypted_macro_block_count) > 0) THEN 'DECRYPTING' ELSE 'NORMAL' END AS STATUS, A.tenant_id as CON_ID FROM (SELECT T.tenant_id, T.table_id, T.table_name, T.table_type, T.tablespace_id, T.tablet_id FROM oceanbase.__all_table T where T.part_level = 0 and T.table_mode >> 12 & 15 in (0,1) UNION ALL SELECT T.tenant_id, T.table_id, T.table_name, T.table_type, T.tablespace_id, P.tablet_id FROM oceanbase.__all_table T, oceanbase.__all_part P WHERE T.part_level = 1 and T.tenant_id = P.tenant_id and T.table_id = P.table_id UNION ALL SELECT T.tenant_id, T.table_id, T.table_name, T.table_type, T.tablespace_id, SP.tablet_id FROM oceanbase.__all_table T, oceanbase.__all_sub_part SP WHERE T.part_level = 2 and T.tenant_id = SP.tenant_id and T.table_id = SP.table_id ) A JOIN oceanbase.__all_tenant_tablespace B ON A.tenant_id = B.tenant_id AND A.tablespace_id = B.tablespace_id JOIN oceanbase.__all_virtual_tablet_encrypt_info E ON E.tenant_id = effective_tenant_id() and E.tablet_id = A.tablet_id WHERE A.tenant_id = 0 AND A.table_type != 12 AND A.table_type != 13 GROUP BY A.tenant_id, A.table_id, A.table_name, B.tablespace_id, B.encryption_name, B.encrypt_key, B.master_key_id )__"))) { LOG_ERROR("fail to set view_definition", K(ret)); } } @@ -560,7 +560,7 @@ int ObInnerTableSchema::v_encrypted_tablespaces_schema(ObTableSchema &table_sche table_schema.set_collation_type(ObCharset::get_default_collation(ObCharset::get_default_charset())); if (OB_SUCC(ret)) { - if (OB_FAIL(table_schema.set_view_definition(R"__( SELECT tablespace_id AS TABLESPACE_ID, encryptionalg AS ENCRYPTIONALG, CASE WHEN encryptionalg != '' AND sum(blocks_decrypted) = 0 THEN 'YES' ELSE 'NO' END AS ENCRYPTED, encryptedkey AS ENCRYPTEDKEY, masterkeyid AS MASTERKEYID, sum(blocks_encrypted) AS BLOCKS_ENCRYPTED, sum(blocks_decrypted) AS BLOCKS_DECRYPTED, CASE WHEN (encryptionalg != '' AND sum(blocks_decrypted) > 0) THEN 'ENCRYPTING' WHEN (encryptionalg = '' AND sum(blocks_encrypted) > 0) THEN 'DECRYPTING' ELSE 'NORMAL' END AS STATUS, con_id AS CON_ID FROM oceanbase.V$OB_ENCRYPTED_TABLES GROUP BY con_id, tablespace_id )__"))) { + if (OB_FAIL(table_schema.set_view_definition(R"__( SELECT tablespace_id AS TABLESPACE_ID, encryptionalg AS ENCRYPTIONALG, CASE WHEN encryptionalg != '' AND sum(blocks_decrypted) = 0 THEN 'YES' ELSE 'NO' END AS ENCRYPTED, encryptedkey AS ENCRYPTEDKEY, masterkeyid AS MASTERKEYID, sum(blocks_encrypted) AS BLOCKS_ENCRYPTED, sum(blocks_decrypted) AS BLOCKS_DECRYPTED, CASE WHEN (encryptionalg != '' AND sum(blocks_decrypted) > 0) THEN 'ENCRYPTING' WHEN (encryptionalg = '' AND sum(blocks_encrypted) > 0) THEN 'DECRYPTING' ELSE 'NORMAL' END AS STATUS, con_id AS CON_ID FROM oceanbase.V$OB_ENCRYPTED_TABLES GROUP BY con_id, tablespace_id, encryptionalg, encryptedkey, masterkeyid )__"))) { LOG_ERROR("fail to set view_definition", K(ret)); } } diff --git a/src/share/inner_table/ob_inner_table_schema_def.py b/src/share/inner_table/ob_inner_table_schema_def.py index 208df689d2..4780ecf51f 100644 --- a/src/share/inner_table/ob_inner_table_schema_def.py +++ b/src/share/inner_table/ob_inner_table_schema_def.py @@ -17792,7 +17792,7 @@ def_table_schema( JOIN oceanbase.__all_virtual_tablet_encrypt_info E ON E.tenant_id = effective_tenant_id() and E.tablet_id = A.tablet_id WHERE A.tenant_id = 0 AND A.table_type != 12 AND A.table_type != 13 - GROUP BY A.tenant_id, A.table_id + GROUP BY A.tenant_id, A.table_id, A.table_name, B.tablespace_id, B.encryption_name, B.encrypt_key, B.master_key_id """.replace("\n", " ") ) @@ -17821,7 +17821,7 @@ def_table_schema( con_id AS CON_ID FROM oceanbase.V$OB_ENCRYPTED_TABLES - GROUP BY con_id, tablespace_id + GROUP BY con_id, tablespace_id, encryptionalg, encryptedkey, masterkeyid """.replace("\n", " ") )