Project

General

Profile

Actions

Feature #10684

closed

We should short-circuit wpdb charset check

Added by Boone Gorges over 5 years ago. Updated about 5 years ago.

Status:
Resolved
Priority name:
Normal
Assignee:
Category name:
Performance
Target version:
Start date:
2018-11-08
Due date:
% Done:

0%

Estimated time:
Deployment actions:

Description

Looking over the processlist log, I see that there is some correspondence between (a) moments when there are many 'sleep' connections, and (b) SHOW FULL COLUMNS queries. The latter queries are, as far as I can see, almost always caused by wpdb::get_table_charset(), which fires very early in the WP bootstrap. WP provides a pre_ filter, which we can use to avoid the query: https://core.trac.wordpress.org/browser/tags/4.9.8/src/wp-includes/wp-db.php?marks=2550-2553,2563#L2536

But there are some potential issues.

1. It looks like our database table encoding is not consistent from table to table. Older tables, like wp_1_posts and wp_users, appears to have utf8_general_ci, while newer tables have multibyte support utf8mb4_unicode_520_ci. This is likely due to failed or incomplete db upgrade routines since 4.2.x. In order for us to be able to hardcode the encoding, we need to know the encoding; this likely means enforcing the same encoding across all tables. I'll do some tests in various places (like cdev) to see what can be done about this. If we can't convert for some reason, we'll instead need to have some way of recording the existing encoding for legacy tables, and building some sort of whitelist. See https://foliovision.com/2015/04/wordpress-database-upgrade-4-2, https://make.wordpress.org/core/2015/04/02/the-utf8mb4-upgrade/

2. The 'pre_get_table_charset' filter runs very early, too early even for an mu-plugin. We need to put the callback in a drop-in, which in our case would have to be object-cache.php or sunrise.php. Or we could introduce db.php, which would contain only the callback + an include statement for wp-db.php. See https://wordpress.stackexchange.com/questions/247109/where-is-the-proper-place-to-add-a-filter-for-pre-get-table-charset

3. It appears that there's a core bug forcing us to add another filter callback alongside pre_get_table_charset. See https://core.trac.wordpress.org/ticket/38921, https://wordpress.stackexchange.com/questions/247109/where-is-the-proper-place-to-add-a-filter-for-pre-get-table-charset

I'll begin to research.


Files

convert-tables.php (1.7 KB) convert-tables.php Boone Gorges, 2018-11-09 12:32 PM
Actions

Also available in: Atom PDF