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. git-svn-id: https://develop.svn.wordpress.org/trunk@37594 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
23d0c953d2
commit
cb5b8479f0
@ -632,7 +632,11 @@ class WP_Meta_Query {
|
||||
}
|
||||
|
||||
if ( $where ) {
|
||||
$sql_chunks['where'][] = "CAST($alias.meta_value AS {$meta_type}) {$meta_compare} {$where}";
|
||||
if ( 'CHAR' === $meta_type ) {
|
||||
$sql_chunks['where'][] = "$alias.meta_value {$meta_compare} {$where}";
|
||||
} else {
|
||||
$sql_chunks['where'][] = "CAST($alias.meta_value AS {$meta_type}) {$meta_compare} {$where}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -493,7 +493,7 @@ class Tests_Meta_Query extends WP_UnitTestCase {
|
||||
) );
|
||||
$sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this );
|
||||
|
||||
$this->assertEquals( 1, substr_count( $sql['where'], "CAST($wpdb->postmeta.meta_value AS CHAR) = ''" ) );
|
||||
$this->assertEquals( 1, substr_count( $sql['where'], "$wpdb->postmeta.meta_value = ''" ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -601,7 +601,7 @@ class Tests_Meta_Query extends WP_UnitTestCase {
|
||||
|
||||
$sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this );
|
||||
|
||||
$this->assertSame( 1, substr_count( $sql['where'], "CAST($wpdb->postmeta.meta_value AS CHAR) = ''" ) );
|
||||
$this->assertSame( 1, substr_count( $sql['where'], "$wpdb->postmeta.meta_value = ''" ) );
|
||||
}
|
||||
|
||||
public function test_get_sql_convert_lowercase_compare_to_uppercase() {
|
||||
@ -632,7 +632,7 @@ class Tests_Meta_Query extends WP_UnitTestCase {
|
||||
|
||||
$sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this );
|
||||
|
||||
$this->assertSame( 1, substr_count( $sql['where'], "CAST($wpdb->postmeta.meta_value AS CHAR) IN" ) );
|
||||
$this->assertSame( 1, substr_count( $sql['where'], "$wpdb->postmeta.meta_value IN" ) );
|
||||
}
|
||||
|
||||
public function test_get_sql_empty_meta_compare_with_non_array_value() {
|
||||
@ -647,7 +647,7 @@ class Tests_Meta_Query extends WP_UnitTestCase {
|
||||
|
||||
$sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this );
|
||||
|
||||
$this->assertSame( 1, substr_count( $sql['where'], "CAST($wpdb->postmeta.meta_value AS CHAR) =" ) );
|
||||
$this->assertSame( 1, substr_count( $sql['where'], "$wpdb->postmeta.meta_value =" ) );
|
||||
}
|
||||
|
||||
public function test_get_sql_invalid_meta_compare() {
|
||||
@ -663,7 +663,7 @@ class Tests_Meta_Query extends WP_UnitTestCase {
|
||||
|
||||
$sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this );
|
||||
|
||||
$this->assertSame( 1, substr_count( $sql['where'], "CAST($wpdb->postmeta.meta_value AS CHAR) =" ) );
|
||||
$this->assertSame( 1, substr_count( $sql['where'], "$wpdb->postmeta.meta_value =" ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -760,7 +760,7 @@ class Tests_Meta_Query extends WP_UnitTestCase {
|
||||
|
||||
$sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this );
|
||||
|
||||
$this->assertSame( 1, substr_count( $sql['where'], "CAST($wpdb->postmeta.meta_value AS CHAR) = 'bar'" ) );
|
||||
$this->assertSame( 1, substr_count( $sql['where'], "$wpdb->postmeta.meta_value = 'bar'" ) );
|
||||
}
|
||||
|
||||
public function test_not_exists() {
|
||||
|
Loading…
Reference in New Issue
Block a user