Bug #113789 information_schema tables not accessible via Table Access Service
Submitted: 29 Jan 2024 9:35 Modified: 29 Jan 2024 9:51
Reporter: Kamil Holubicki (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Information schema Severity:S3 (Non-critical)
Version:8.0 OS:Any
Assigned to: Marc ALFF CPU Architecture:Any
Tags: Contribution

[29 Jan 2024 9:35] Kamil Holubicki
Description:
It is not possible to access information_schema.plugins table via Table Access Service. The code analysis shows that it is not possible also for other i_s tables.

How to repeat:
I have attached a simple component implementation (my_component) that tries to access information_schema plugins table using Table Access Component.

This example is loosely based on the demo presented here https://archive.fosdem.org/2022/schedule/event/mysql_component/ by Joro Kodinov. It is a dirty implementation just to demonstrate the problem.

1. put the component directory into mysql-server/components directory
2. compile the server and the component
3. start mysqld with the right --plugin-dir containing the component binary
4. INSTALL COMPONENT "file://component_my_component";

The component is dumping its output into the error log.

The expected result is to have plugin_name and plugin_status columns dumped to the server error log every 10 seconds.

Instead of this, we fail during the table access begin which results in log: ta_srv->begin() error

Suggested fix:
The reason seems to be table_access_service, which does not set necessary members of Table_ref structure from m_table_array.
In particular, Table_ref::schema_table is not set. It is necessary in sql_base.cc::open_and_process_table() because we need to call mysql_schema_table(). In the normal query flow, Table_ref::schema_table is set in Query_block::add_table_to_list().
Even after setting Table_ref::schema_table thd::init_cost_model() has to be called, because of the assertions.
Of course, proper disposal of temp table used by the query is needed afterwards.

Also, two small modifications were necessary in sql_show.cc (checks for query_bock being nullptr)

I attached patched table_access_service.cc which allowed me to query I_S tables. Please note that this is rather a dirty patch that allows the "happy path" to work, but I think it demonstrates the problem well.
[29 Jan 2024 9:36] Kamil Holubicki
test component

(*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: my_component.tgz (application/x-compressed-tar, text), 20.00 KiB.

[29 Jan 2024 9:36] Kamil Holubicki
Patch allowing access to i_s

(*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: i_s_patch.diff (text/x-patch), 2.82 KiB.

[29 Jan 2024 9:51] MySQL Verification Team
Hello Kamil Holubicki ,

Thank you for the report and contribution.

regards,
Umesh