[wp-trac] [WordPress Trac] #36625: Don't CAST the post meta value to CHAR in meta query
WordPress Trac
noreply at wordpress.org
Thu Apr 21 20:02:36 UTC 2016
#36625: Don't CAST the post meta value to CHAR in meta query
-------------------------+-----------------------------
Reporter: ericlewis | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Query | Version: 3.1
Severity: normal | Keywords:
Focuses: |
-------------------------+-----------------------------
This topic came up in
[https://core.trac.wordpress.org/ticket/19738#comment:10 19738], and
warrants its own ticket.
Before r15724 (see #9124), if you had a post with meta for `rating` of 100
and performed a meta query looking for posts with a `rating` higher than
50, the query would not return that post. This is because the MySQL
generated for WP_Query performed a string comparison, as both sides of the
comparison were strings, e.g. `wp_postmeta.meta_value > '50'`.
This led to the introduction of the meta query `type` parameter. Provide a
MySQL data type, and the meta value is cast to that type in the SQL query.
A default was set to cast the `meta_value` column to `CHAR`. Casting the
meta value to CHAR is redundant, as the `meta_value` column is `LONGTEXT`,
which is already a string type.
Removing this cast in the SQL generated by WP_Query allows users to add an
index for the meta_value column and have that index considered for use by
the MySQL optimizer on execution.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/36625>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list