Skip to content

Commit 8f00f59

Browse files
author
boonebgorges
committed
In WP_Meta_Query, don't cast meta_value to CHAR.
`CHAR` is redundant, since the `meta_value` column is `LONGTEXT`. Meanwhile, use of `CAST()` causes MySQL to ignore any index that the administrator may have added to the column. A number of automated tests were doing searches for `CAST` in the SQL strings generated by `WP_Meta_Query` (for reasons unrelated to the `CAST()` behavior). These tests have been updated to expect the new query format. Props ericlewis. Fixes #36625. Built from https://develop.svn.wordpress.org/trunk@37594
1 parent f328836 commit 8f00f59

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

wp-includes/class-wp-meta-query.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,11 @@ public function get_sql_for_clause( &$clause, $parent_query, $clause_key = '' )
632632
}
633633

634634
if ( $where ) {
635-
$sql_chunks['where'][] = "CAST($alias.meta_value AS {$meta_type}) {$meta_compare} {$where}";
635+
if ( 'CHAR' === $meta_type ) {
636+
$sql_chunks['where'][] = "$alias.meta_value {$meta_compare} {$where}";
637+
} else {
638+
$sql_chunks['where'][] = "CAST($alias.meta_value AS {$meta_type}) {$meta_compare} {$where}";
639+
}
636640
}
637641
}
638642

wp-includes/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* @global string $wp_version
66
*/
7-
$wp_version = '4.6-alpha-37593';
7+
$wp_version = '4.6-alpha-37594';
88

99
/**
1010
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

0 commit comments

Comments
 (0)