MySQL enhancements / slow queries
-
Hi, after troubleshooting our installation (wordpress 6.1,
TranslatePress – Multilingual 2.4.2), i found out that gettext mysql tables are not-optimal and some slow queries, resolving these issues in source code and database manually solved our issues (slow rendering of each page)So for anyone, and maybe developers of translate-press even, here’s what i did:
(1) missing indexes
eg. wp433_trp_gettext_en_gb missing index/key on columns “domain”, “original_id” (and maybe “status”)
-> manually via phpmyadmin, in each gettext table structure, add “index” to at least those 2 columnsoriginal create table query
CREATE TABLE
wp433_trp_gettext_en_gb
(
id
bigint(20) NOT NULL AUTO_INCREMENT,
original
longtext NOT NULL,
translated
longtext DEFAULT NULL,
domain
longtext DEFAULT NULL,
status
int(20) DEFAULT NULL,
original_id
bigint(20) DEFAULT NULL,
plural_form
int(20) DEFAULT NULL,
PRIMARY KEY (id
),
UNIQUE KEYid
(id
),
KEYindex_name
(original
(100)),
KEYdomain
(domain
(768)),
KEYstatus
(status
),
KEYoriginal_id
(original_id
),
FULLTEXT KEYoriginal_fulltext
(original
)
) ENGINE=InnoDB AUTO_INCREMENT=24464 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`updated create table
CREATE TABLE
wp433_trp_gettext_en_gb` (
id
bigint(20) NOT NULL AUTO_INCREMENT,
original
longtext NOT NULL,
translated
longtext DEFAULT NULL,
domain
longtext DEFAULT NULL,
status
int(20) DEFAULT NULL,
original_id
bigint(20) DEFAULT NULL,
plural_form
int(20) DEFAULT NULL,
PRIMARY KEY (id
),
UNIQUE KEYid
(id
),
KEYindex_name
(original
(100)),
// => these keys are added
KEYdomain
(domain
(768)),
KEYstatus
(status
),
KEYoriginal_id
(original_id
),
// => end of modifications
FULLTEXT KEYoriginal_fulltext
(original
)
) ENGINE=InnoDB AUTO_INCREMENT=24464 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`(2) slow query involving union/distinct/collate
method: translatepress-multilingual/includes/string-translation/class-string-translation.php::TRP_String_Translation::get_gettext_domains
default constructed query looks like this:
SELECT domain FROM wp433_trp_gettext_en_gb UNION SELECT domain FROM wp433_trp_gettext_en_us UNION SELECT domain FROM wp433_trp_gettext_cs_cz ORDER BY domain ASC;
this uses UNION(DISTINCT) and ORDER and takes about 1.7 seconds on MariaDB 10.5.18
-> manually updated function to use “UNION ALL” and not add “order by”, this took the query down to 0.075 second
- The topic ‘MySQL enhancements / slow queries’ is closed to new replies.