WordPress.org

Make WordPress Core


Ignore:
Timestamp:
05/30/2016 04:35:16 AM (5 years ago)
Author:
boonebgorges
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-meta-query.php

    r37492 r37594  
    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        }
Note: See TracChangeset for help on using the changeset viewer.