[wp-trac] [WordPress Trac] #64090: Unexpected DB query when inserting a non-hierarchical term
WordPress Trac
noreply at wordpress.org
Sat Oct 11 06:58:04 UTC 2025
#64090: Unexpected DB query when inserting a non-hierarchical term
-------------------------------------------------+-------------------------
Reporter: Chouby | Owner:
| spacedmonkey
Type: enhancement | Status: assigned
Priority: normal | Milestone: 6.9
Component: Taxonomy | Version:
Severity: normal | Resolution:
Keywords: needs-unit-tests good-first-bug | Focuses:
has-patch | performance
-------------------------------------------------+-------------------------
Comment (by rollybueno):
Run the test on both trunk and https://github.com/WordPress/wordpress-
develop/pull/10216/. The difference is that, on trunk we got extra query,
which confirms the issue reproduction:
{{{
SELECT autoload FROM wptests_options WHERE option_name =
'post_tag_children'
}}}
while on the https://github.com/WordPress/wordpress-develop/pull/10216/ we
got none. Below is the **before and after** test result, printing the
queries:
**trunk**:
{{{
Array
(
[0] => SELECT t.term_id
FROM wptests_terms AS t INNER JOIN
wptests_term_taxonomy AS tt ON t.term_id = tt.term_id
WHERE tt.taxonomy IN ('post_tag') AND t.name IN
('test') AND tt.parent = '0'
ORDER BY t.name ASC
[1] => SELECT t.term_id
FROM wptests_terms AS t INNER JOIN
wptests_term_taxonomy AS tt ON t.term_id = tt.term_id
WHERE t.slug IN ('test')
ORDER BY t.term_id ASC
LIMIT 1
[2] => SELECT t.term_id
FROM wptests_terms AS t INNER JOIN
wptests_term_taxonomy AS tt ON t.term_id = tt.term_id
WHERE t.name IN ('test')
ORDER BY t.term_id ASC
LIMIT 1
[3] => INSERT INTO `wptests_terms` (`name`, `slug`, `term_group`)
VALUES ('test', 'test', 0)
[4] => SELECT tt.term_taxonomy_id FROM wptests_term_taxonomy AS tt
INNER JOIN wptests_terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy
= 'post_tag' AND t.term_id = 5
[5] => INSERT INTO `wptests_term_taxonomy` (`term_id`, `taxonomy`,
`description`, `parent`, `count`) VALUES (5, 'post_tag', '', 0, 0)
[6] => SELECT t.term_id, t.slug, tt.term_taxonomy_id, tt.taxonomy FROM
wptests_terms AS t INNER JOIN wptests_term_taxonomy AS tt ON ( tt.term_id
= t.term_id ) WHERE t.slug = 'test' AND tt.parent = 0 AND tt.taxonomy =
'post_tag' AND t.term_id < 5 AND tt.term_taxonomy_id != 5
[7] => SELECT autoload FROM wptests_options WHERE option_name =
'post_tag_children'
)
}}}
**PR 10216**:
{{{
Array
(
[0] => SELECT t.term_id
FROM wptests_terms AS t INNER JOIN
wptests_term_taxonomy AS tt ON t.term_id = tt.term_id
WHERE tt.taxonomy IN ('post_tag') AND t.name IN
('test') AND tt.parent = '0'
ORDER BY t.name ASC
[1] => SELECT t.term_id
FROM wptests_terms AS t INNER JOIN
wptests_term_taxonomy AS tt ON t.term_id = tt.term_id
WHERE t.slug IN ('test')
ORDER BY t.term_id ASC
LIMIT 1
[2] => SELECT t.term_id
FROM wptests_terms AS t INNER JOIN
wptests_term_taxonomy AS tt ON t.term_id = tt.term_id
WHERE t.name IN ('test')
ORDER BY t.term_id ASC
LIMIT 1
[3] => INSERT INTO `wptests_terms` (`name`, `slug`, `term_group`)
VALUES ('test', 'test', 0)
[4] => SELECT tt.term_taxonomy_id FROM wptests_term_taxonomy AS tt
INNER JOIN wptests_terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy
= 'post_tag' AND t.term_id = 5
[5] => INSERT INTO `wptests_term_taxonomy` (`term_id`, `taxonomy`,
`description`, `parent`, `count`) VALUES (5, 'post_tag', '', 0, 0)
[6] => SELECT t.term_id, t.slug, tt.term_taxonomy_id, tt.taxonomy FROM
wptests_terms AS t INNER JOIN wptests_term_taxonomy AS tt ON ( tt.term_id
= t.term_id ) WHERE t.slug = 'test' AND tt.parent = 0 AND tt.taxonomy =
'post_tag' AND t.term_id < 5 AND tt.term_taxonomy_id != 5
)
}}}
Hey @Chouby - I suggest we should add the same test unit on the PR as
well. Maybe somewhere in **wpInsertTerm.php**
--
Ticket URL: <https://core.trac.wordpress.org/ticket/64090#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list