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/tests/phpunit/tests/meta/query.php

    r32713 r37594  
    494494        $sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this );
    495495
    496         $this->assertEquals( 1, substr_count( $sql['where'], "CAST($wpdb->postmeta.meta_value AS CHAR) = ''" ) );
     496        $this->assertEquals( 1, substr_count( $sql['where'], "$wpdb->postmeta.meta_value = ''" ) );
    497497    }
    498498
     
    602602        $sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this );
    603603
    604         $this->assertSame( 1, substr_count( $sql['where'], "CAST($wpdb->postmeta.meta_value AS CHAR) = ''" ) );
     604        $this->assertSame( 1, substr_count( $sql['where'], "$wpdb->postmeta.meta_value = ''" ) );
    605605    }
    606606
     
    633633        $sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this );
    634634
    635         $this->assertSame( 1, substr_count( $sql['where'], "CAST($wpdb->postmeta.meta_value AS CHAR) IN" ) );
     635        $this->assertSame( 1, substr_count( $sql['where'], "$wpdb->postmeta.meta_value IN" ) );
    636636    }
    637637
     
    648648        $sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this );
    649649
    650         $this->assertSame( 1, substr_count( $sql['where'], "CAST($wpdb->postmeta.meta_value AS CHAR) =" ) );
     650        $this->assertSame( 1, substr_count( $sql['where'], "$wpdb->postmeta.meta_value =" ) );
    651651    }
    652652
     
    664664        $sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this );
    665665
    666         $this->assertSame( 1, substr_count( $sql['where'], "CAST($wpdb->postmeta.meta_value AS CHAR) =" ) );
     666        $this->assertSame( 1, substr_count( $sql['where'], "$wpdb->postmeta.meta_value =" ) );
    667667    }
    668668
     
    761761        $sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this );
    762762
    763         $this->assertSame( 1, substr_count( $sql['where'], "CAST($wpdb->postmeta.meta_value AS CHAR) = 'bar'" ) );
     763        $this->assertSame( 1, substr_count( $sql['where'], "$wpdb->postmeta.meta_value = 'bar'" ) );
    764764    }
    765765
Note: See TracChangeset for help on using the changeset viewer.