Closed SamTyurenkov closed 5 months ago
Can you post the full SQL command? It looks like it's https://dev.mysql.com/doc/refman/8.0/en/show-table-status.html which is indeed not handled.
Looks like we need to add a rewriter for that to emulate behavior. Per the docs it's similar to show tables which is already implemented but provides some additional info we need to emulate
@mattbucci already not at pc, but its easily reproducable when visiting site health page in dashboard i think.
Maybe you can find the SQL in core files as per trace message: /wp-admin/includes/class-wp-debug-data.php(1574) and add the error_log just before it to get the SQL.
I visited the site health dashboard as part of https://github.com/PostgreSQL-For-Wordpress/postgresql-for-wordpress/pull/91
I did not see this command executed
@mattbucci I really wont be at that project until Monday, but did you visit both tabs on site health page? maybe the second tab generates that SQL
yes I visited both tabs
updated original message, with full stack trace and full SQL command, which is just "SHOW TABLE STATUS" without anything else. it is called by core method
finally able to take a look at this.
Not seeing the issue with SHOW TABLE STATUS, but getting another error:
SELECT TABLE_NAME AS 'table', TABLE_ROWS AS 'rows', SUM(data_length + index_length) as 'bytes' FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'wordpress' AND TABLE_NAME IN ('wp_comments','wp_options','wp_posts','wp_terms','wp_users') GROUP BY TABLE_NAME;
This has lots of problems as information_schema looks nothing like this.
TABLE_SCHEMA
is being set to wordpress
which is not correct, it should be public, or even better extracted to a constant which can be set. wordpress is my db name. Additionally it should be lowercase, table_schema
TABLE_ROWS
, data_length
, index_length
all don't exist
it should look like this I think
SELECT
C.relname AS "table",
S.n_live_tup AS "rows",
pg_total_relation_size(C.oid) AS "bytes"
FROM
pg_class C
LEFT JOIN
pg_namespace N ON (N.oid = C.relnamespace)
INNER JOIN
pg_stat_user_tables S ON (S.relid = C.oid)
WHERE
N.nspname = 'public' AND
C.relname IN ('wp_comments','wp_options','wp_posts','wp_terms','wp_users')
GROUP BY
C.relname, pg_total_relation_size(C.oid), S.n_live_tup;
That comes from should_suggest_persistent_object_cache
not really a point in trying to fix the schema, better to just detect this query and rewrite the whole thing from scratch in the select rewriter, this also doesn't get triggered by multisite installs, only single sites
// With InnoDB the `TABLE_ROWS` are estimates, which are accurate enough and faster to retrieve than individual `COUNT()` queries.
$results = $wpdb->get_results(
$wpdb->prepare(
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- This query cannot use interpolation.
"SELECT TABLE_NAME AS 'table', TABLE_ROWS AS 'rows', SUM(data_length + index_length) as 'bytes' FROM information_schema.TABLES WHERE TABLE_SCHEMA = %s AND TABLE_NAME IN ('$table_names') GROUP BY TABLE_NAME;",
DB_NAME
),
OBJECT_K
);
Ok, so as far as SHOW TABLE STATUS goes, there's a lot to emulate.
The function you referenced only includes data_length and index_length. Those are straightforward enough. Here's the full set though
Name: The name of the table.
Engine: The storage engine for the table (MyISAM, InnoDB, etc.).
Version: The version number of the table's .frm file.
Row_format: The row storage format (Compact or Redundant) for InnoDB tables or the row storage format (Fixed, Dynamic, or Compressed) for MyISAM tables.
Rows: The number of rows. Some storage engines, like InnoDB, provide only an approximation.
Avg_row_length: The average row length.
Data_length: The length (bytes) of the data file (how much space the actual data takes).
Max_data_length: The maximum length of data file for the table.
Index_length: The length (bytes) of the index file (how much space the indexed data takes).
Data_free: The number of allocated but unused bytes.
Auto_increment: The next autoincrement value.
Create_time: When the table was created.
Update_time: When the data file was last updated.
Check_time: When the table was last checked.
Table_collation: The table's character set and collation.
Checksum: The live checksum or the last calculated checksum.
Create_options: Extra options that were specified with CREATE TABLE.
Comment: Any comment that was included in the COMMENT option when the table was created.
Here's the basic emulated query
SELECT
relname AS Name,
pg_relation_size(relid) AS Data_length,
pg_indexes_size(relid) AS Index_length
FROM
pg_stat_user_tables
ORDER BY
pg_total_relation_size(relid) DESC;
I will add this for now, with dummy values for other columns, but we should aim to improve emulation here
There is now a PR available if you'd like to test it: https://github.com/PostgreSQL-For-Wordpress/postgresql-for-wordpress/pull/100/files
environment: -wordpress 6.4.3 on roots bedrock -docker pg16.1, php8.1-fpm
Full SQL command is SHOW TABLE STATUS