Open
Description
What would you like to be improved?
According to the CPU profiler,

The following code is very time-consuming; we need to merge the logic of fetching the table as much as possible
The SQL corresponding to getColumnsByTableIdAndVersion
can be optimized:
mysql> select
-> *
-> from
-> table_column_version_info t1
-> inner join (
-> SELECT
-> column_id,
-> MAX(table_version) AS max_table_version
-> from
-> table_column_version_info
-> where
-> table_id = 2716478369449788787
-> and table_version <= 10
-> and deleted_at = 0
-> group by
-> column_id
-> ) t2 on t1.column_id = t2.column_id
-> AND t1.table_version = t2.max_table_version;
8 rows in set (0.28 sec)
mysql> select
-> *
-> from
-> table_column_version_info t1
-> inner join (
-> SELECT
-> column_id,
-> MAX(table_version) AS max_table_version
-> from
-> table_column_version_info
-> where
-> table_id = 2716478369449788787
-> and table_version <= 10
-> and deleted_at = 0
-> group by
-> column_id
-> ) t2 on t1.column_id = t2.column_id
-> AND t1.table_version = t2.max_table_version
-> and table_id = 2716478369449788787;
8 rows in set (0.00 sec)
If we add a condition like table_id = xxxx
in the end, It will more efficient.
How should we improve?
No response
Activity