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

[Bug]: Error occurs when querying system tables #15331

Closed
1 task done
DanielZhangQD opened this issue Apr 3, 2024 · 10 comments
Closed
1 task done

[Bug]: Error occurs when querying system tables #15331

DanielZhangQD opened this issue Apr 3, 2024 · 10 comments
Assignees
Labels
impact/1.1 kind/bug Something isn't working phase/testing resolved/v1.1.3 severity/s0 Extreme impact: Cause the application to break down and seriously affect the use
Milestone

Comments

@DanielZhangQD
Copy link
Contributor

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

1.1.2

Commit ID

v1.1.2-1519f8e5c-2024-04-02

Other Environment Information

- Hardware parameters:
- OS type:
- Others:

Actual Behavior

Run the following SQL with user account:

MySQL [(none)]> SELECT relname AS `name`, mo_table_rows(reldatabase, relname) AS `rows`, mo_table_size(reldatabase, relname) AS `size`, if (role_name IS NULL, '-', role_name) AS `owner`, mo_tables.created_time AS created FROM mo_catalog.mo_tables LEFT JOIN mo_catalog.mo_role ON mo_catalog.mo_tables.owner=role_id WHERE relkind IN ('r','e','cluster') AND reldatabase='test' Order by name;
ERROR 1064 (HY000): SQL parser error: table "" does not exist

Run the following SQL with dump:

MySQL [(none)]> SELECT relname AS `name`, mo_table_rows(reldatabase, relname) AS `rows`, mo_table_size(reldatabase, relname) AS `size`, if (role_name IS NULL, '-', role_name) AS `owner`, mo_tables.created_time AS created FROM mo_catalog.mo_tables LEFT JOIN mo_catalog.mo_role ON mo_catalog.mo_tables.owner=role_id WHERE relkind IN ('r','e','cluster') AND reldatabase='test' Order by name;
ERROR 20203 (HY000): invalid argument db not found when mo_table_rows, bad value test

Expected Behavior

SQL succeeds

Steps to Reproduce

See detail in Actual Behavior

Additional information

Cloud prod

@DanielZhangQD DanielZhangQD added kind/bug Something isn't working needs-triage severity/s0 Extreme impact: Cause the application to break down and seriously affect the use labels Apr 3, 2024
@DanielZhangQD DanielZhangQD added this to the 1.2.0 milestone Apr 3, 2024
@sukki37
Copy link
Contributor

sukki37 commented Apr 3, 2024

cause by mo_table_size function, it can be reproduced by executing

select mo_table_size(reldatabase, relname) from mo_catalog.mo_tables where relkind IN ('r','e','cluster');
image

@sukki37 sukki37 assigned gouhongshen and unassigned matrix-meow Apr 3, 2024
@gouhongshen
Copy link
Contributor

gouhongshen commented Apr 7, 2024

two issus:

  1. why invalid argument db not found when mo_table_rows, bad value test when run with dump
  2. why SQL parser error: table "" does not exist with other account

for issue 1:

the db "test" is not exist on the account dump, so it cannot be retrive by account dump(account id 0).
the simple fix can be:

select mo_table_size(reldatabase, relname) from mo_catalog.mo_tables where relkind IN ('r','e','cluster') and mo_catalog.mo_tables.account_id = ( select current_account_id() as cur_acc_id).

@gouhongshen
Copy link
Contributor

gouhongshen commented Apr 7, 2024

for issue 2, seems it is related to tables test.ecbase_card and test.realname_order_info

mysql> SELECT reldatabase, relname AS `name`, if (role_name IS NULL, '-', role_name) AS `owner`, mo_tables.created_time AS created FROM mo_catalog.mo_tables LEFT JOIN mo_catalog.mo_role ON mo_catalog.mo_tables.owner=role_id WHERE relkind IN ('r','e','cluster') AND reldatabase='test' Order by name;
+-------------+---------------------+--------------+---------------------+
| reldatabase | name                | owner        | created             |
+-------------+---------------------+--------------+---------------------+
| test        | ecbase_card         | accountadmin | 2024-01-19 08:42:31 |
| test        | realname_order_info | accountadmin | 2024-01-19 08:42:31 |
| test        | t1                  | accountadmin | 2023-11-13 09:35:43 |
| test        | t2                  | accountadmin | 2024-04-02 01:41:01 |
| test        | t3                  | accountadmin | 2024-04-02 02:05:05 |
| test        | t4                  | accountadmin | 2024-04-02 02:05:50 |
| test        | t5                  | accountadmin | 2024-04-02 02:06:05 |
| test        | your_table          | accountadmin | 2024-02-04 15:34:26 |
+-------------+---------------------+--------------+---------------------+
8 rows in set (0.07 sec)

without these two tables, things go fine.

mysql> SELECT reldatabase, relname, mo_table_rows(reldatabase, relname) AS `rows`, mo_table_size(reldatabase, relname) AS `size`, if (role_name IS NULL, '-', role_name) AS `owner`, mo_tables.created_time AS created FROM mo_catalog.mo_tables LEFT JOIN mo_catalog.mo_role ON mo_catalog.mo_tables.owner=role_id WHERE relkind IN ('r','e','cluster') AND reldatabase='test' and relname not in ("ecbase_card","realname_order_info") Order by relname;
+-------------+------------+------+------+--------------+---------------------+
| reldatabase | relname    | rows | size | owner        | created             |
+-------------+------------+------+------+--------------+---------------------+
| test        | t1         |    3 |  716 | accountadmin | 2023-11-13 09:35:43 |
| test        | t2         |    0 |    0 | accountadmin | 2024-04-02 01:41:01 |
| test        | t3         |    0 |    0 | accountadmin | 2024-04-02 02:05:05 |
| test        | t4         |    0 |    0 | accountadmin | 2024-04-02 02:05:50 |
| test        | t5         |    0 |    0 | accountadmin | 2024-04-02 02:06:05 |
| test        | your_table |    0 |    0 | accountadmin | 2024-02-04 15:34:26 |
+-------------+------------+------+------+--------------+---------------------+
6 rows in set (0.07 sec)

@gouhongshen
Copy link
Contributor

db mysql has the same behaviour:

mysql> select reldatabase, relname, mo_table_size(reldatabase, relname) from mo_catalog.mo_tables where relkind in ('e', 'r', 'cluster') and reldatabase = "mysql" and relname not in ("db", "procs_priv", "tables_priv");
+-------------+--------------+-------------------------------------+
| reldatabase | relname      | mo_table_size(reldatabase, relname) |
+-------------+--------------+-------------------------------------+
| mysql       | role_edges   |                                   0 |
| mysql       | user         |                                   0 |
| mysql       | columns_priv |                                   0 |
+-------------+--------------+-------------------------------------+

all these excluded tables have secondary key.

@gouhongshen
Copy link
Contributor

gouhongshen commented Apr 7, 2024

https://grafana.matrixonecloud.cn/explore?panes=%7B%22Iej%22:%7B%22datasource%22:%22fe9f0f46-57bd-4343-8755-8d67d0429b65%22,%22queries%22:%5B%7B%22refId%22:%22A%22,%22expr%22:%22%7Bnamespace%3D%5C%22hongshen-test%5C%22%7D%20%7C%3D%20%60err%5BSQL%20parser%60%22,%22queryType%22:%22range%22,%22datasource%22:%7B%22type%22:%22loki%22,%22uid%22:%22fe9f0f46-57bd-4343-8755-8d67d0429b65%22%7D,%22editorMode%22:%22builder%22%7D%5D,%22range%22:%7B%22from%22:%22now-3h%22,%22to%22:%22now%22%7D%7D%7D&schemaVersion=1&orgId=1

test db:

{"level":"INFO","time":"2024/04/07 14:18:43.782190 +0000","caller":"function/func_mo.go:326","msg":"getIndexesSize: [ecbase_card]: [__mo_index_unique_af2e51bb-b6a6-11ee-8ead-96414838c38d];[];err[SQL parser error: table \"\" does not exist]\n"}


 mysql db:
 
{"level":"INFO","time":"2024/04/07 14:29:39.144631 +0000","caller":"function/func_mo.go:326","msg":"getIndexesSize: [db]: [];err[SQL parser error: table \"\" does not exist]\n"}

so the table "" does not exist err is caused by an empty indexTableName.

another question: why the indexTableName is empty?

@gouhongshen
Copy link
Contributor

https://grafana.matrixonecloud.cn/explore?panes=%7B%22Iej%22:%7B%22datasource%22:%22fe9f0f46-57bd-4343-8755-8d67d0429b65%22,%22queries%22:%5B%7B%22refId%22:%22A%22,%22expr%22:%22%7Bnamespace%3D%5C%22hongshen-test%5C%22%7D%20%7C%3D%20%60has%20index%60%22,%22queryType%22:%22range%22,%22datasource%22:%7B%22type%22:%22loki%22,%22uid%22:%22fe9f0f46-57bd-4343-8755-8d67d0429b65%22%7D,%22editorMode%22:%22builder%22%7D%5D,%22range%22:%7B%22from%22:%22now-15m%22,%22to%22:%22now%22%7D%7D%7D&schemaVersion=1&orgId=1

{"level":"INFO","time":"2024/04/07 15:12:23.826051 +0000","caller":"disttae/txn_table.go:1199","msg":"table db has indexes: indexTableName:, indexName:user, indexAlgo:, indexVisible:false, indexAlgoParams:, indexAlgoTableType:, indexUnique:false, indexTableExist:false, indexComment:, indexParts:[user]\n"}
{"level":"INFO","time":"2024/04/07 15:10:31.830762 +0000","caller":"disttae/txn_table.go:1199","msg":"table ecbase_card has indexes: indexTableName:__mo_index_unique_af2e51bb-b6a6-11ee-8ead-96414838c38d, indexName:uk_ecbase_card_vc_icciddfaf, indexAlgo:, indexVisible:false, indexAlgoParams:, indexAlgoTableType:, indexUnique:true, indexTableExist:true, indexComment:20231021新增, indexParts:[vccodedosedf icciddfaf]\nindexTableName:, indexName:ecbase_card_ecbase_company_id_fk, indexAlgo:, indexVisible:false, indexAlgoParams:, indexAlgoTableType:, indexUnique:false, indexTableExist:false, indexComment:, indexParts:[company_id]\nindexTableName:, indexName:ecbase_card_subs_id, indexAlgo:, indexVisible:false, indexAlgoParams:, indexAlgoTableType:, indexUnique:false, indexTableExist:false, indexComment:, indexParts:[subs_id]\nindexTableName:, indexName:idx_ecbase_card_vin, indexAlgo:, indexVisible:false, indexAlgoParams:, indexAlgoTableType:, indexUnique:false, indexTableExist:false, indexComment:, indexParts:[vinodk]\nindexTableName:, indexName:ecbase_card_code_carrier_card_status_idx, indexAlgo:, indexVisible:false, indexAlgoParams:, indexAlgoTableType:, indexUnique:false, indexTableExist:false, indexComment:, indexParts:[code carrier]\nindexTableName:, indexName:ecbase_card_code_vehicle_status_idx, indexAlgo:, indexVisible:false, indexAlgoParams:, indexAlgoTableType:, indexUnique:false, indexTableExist:false, indexComment:, indexParts:[code vehicle_status]\nindexTableName:, indexName:ecbase_card_code_realname_status_idx, indexAlgo:, indexVisible:false, indexAlgoParams:, indexAlgoTableType:, indexUnique:false, indexTableExist:false, indexComment:, indexParts:[code status]\nindexTableName:, indexName:idx_account_id, indexAlgo:, indexVisible:false, indexAlgoParams:, indexAlgoTableType:, indexUnique:false, indexTableExist:false, indexComment:, indexParts:[account_id]\nindexTableName:, indexName:idx_ecbase_card_msisdn123, indexAlgo:, indexVisible:false, indexAlgoParams:, indexAlgoTableType:, indexUnique:false, indexTableExist:false, indexComment:, indexParts:[msisdn123]\nindexTableName:, indexName:ecbase_card_code_icciddfaf_idx, indexAlgo:, indexVisible:false, indexAlgoParams:, indexAlgoTableType:, indexUnique:false, indexTableExist:false, indexComment:, indexParts:[code icciddfaf]\nindexTableName:, indexName:idx_vc, indexAlgo:, indexVisible:false, indexAlgoParams:, indexAlgoTableType:, indexUnique:false, indexTableExist:false, indexComment:, indexParts:[vccodedosedf]\nindexTableName:, indexName:ecbase_card_icciddfaf, indexAlgo:, indexVisible:false, indexAlgoParams:, indexAlgoTableType:, indexUnique:false, indexTableExist:false, indexComment:2310.7新增, indexParts:[icciddfaf]\n"}

@sukki37 sukki37 modified the milestones: 1.2.0, 1.1.0 Apr 7, 2024
@gouhongshen
Copy link
Contributor

gouhongshen commented Apr 10, 2024

#15403 只是忽视了该错误,避免 mo_table_size 因为它报错。忽视该错误只会影响 mo_table_size 的准确性,因为可能会少统计若干个索引表的大小。

更深的原因可能与 commit 到 tn 的 constraint 数据 中的 index 信息完整性有关。之前没有发现,是因为该 index name 信息未被消费,升级到 112 后,mo_table_size 消费了该信息,从而引发了该问题。

验证方式:
prod 和 qa 上的 dump 和 6d966d73_a195_437e_88f8_7f75b3cc6496 租户存在该问题。
只需要在包含该 fix 的 CN 上对上面租户执行查询:

SELECT relname AS `name`, mo_table_size(reldatabase, relname) AS `size`, if (role_name IS NULL, '-', role_name) AS `owner`, mo_tables.created_time AS created FROM mo_catalog.mo_tables LEFT JOIN mo_catalog.mo_role ON mo_catalog.mo_tables.owner=role_id WHERE relkind IN ('r','e','cluster') and account_id = (select current_account_id() as acc) Order by name;

没有错误就是修复了。

@TangxingZhou
Copy link

dump账号执行:

SELECT relname AS `name`, mo_table_size(reldatabase, relname) AS `size`, if (role_name IS NULL, '-', role_name) AS `owner`, mo_tables.created_time AS created FROM mo_catalog.mo_tables LEFT JOIN mo_catalog.mo_role ON mo_catalog.mo_tables.owner=role_id WHERE relkind IN ('r','e','cluster') and account_id = (select current_account_id() as acc) and account_id = (select current_account_id() as acc) Order by name;

dump不带 and account_id = (select current_account_id() as acc) 过滤条件会执行出错

@TangxingZhou
Copy link

暂无业务使用dump账户去执行该SQL,如果有需求,需要产品设计

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
impact/1.1 kind/bug Something isn't working phase/testing resolved/v1.1.3 severity/s0 Extreme impact: Cause the application to break down and seriously affect the use
Projects
None yet
Development

No branches or pull requests

6 participants