[wp-hackers] meta query crashing database

Steve Taylor steve at sltaylor.co.uk
Thu Sep 1 17:34:39 UTC 2011


Thanks Michael, exactly right :)


On 1 September 2011 00:19, Michael Van Winkle <mike at mikevanwinkle.com> wrote:
> You'd probably do better with the MySQL IN operator, since each meta
> query is a join (an expensive MySQL operation).
>
> $query['meta_query'] = array(
>  array(
>   'key'=>'slt_issues',
>   'value'=>array(112,113,114,115,115),
>   'compare'=>'IN'
>  )
> );
>
>
> On Wed, Aug 31, 2011 at 4:10 PM, Steve Taylor <steve at sltaylor.co.uk> wrote:
>> I'm trying to build a query. I have a CPT, "campaigns", which is
>> related to one or more "issues" (also a CPT).
>>
>> The relationship is managed by a custom meta box on the campaigns edit
>> screen, you select the issues. It stores one or more entries in the
>> postmeta table, each having the ID of the issue.
>>
>> What I need to do is, for the single campaign template, grab a list of
>> "related" campaigns. So I need to grab all other campaigns that are
>> related to any of the issues that the campaign being viewed is related
>> to. The dump of the WP_Query arguments, for campaign ID 851, with a
>> bunch of related issues, is this:
>>
>> Array
>> (
>>    [post_type] => campaign
>>    [posts_per_page] => -1
>>    [post__not_in] => Array
>>        (
>>            [0] => 851
>>        )
>>    [meta_query] => Array
>>        (
>>            [relation] => OR
>>            [0] => Array
>>                (
>>                    [key] => _slt_issues
>>                    [value] => 185
>>                )
>>            [1] => Array
>>                (
>>                    [key] => _slt_issues
>>                    [value] => 194
>>                )
>>            [2] => Array
>>                (
>>                    [key] => _slt_issues
>>                    [value] => 193
>>                )
>>            [3] => Array
>>                (
>>                    [key] => _slt_issues
>>                    [value] => 187
>>                )
>>            [4] => Array
>>                (
>>                    [key] => _slt_issues
>>                    [value] => 191
>>                )
>>            [5] => Array
>>                (
>>                    [key] => _slt_issues
>>                    [value] => 189
>>                )
>>            [6] => Array
>>                (
>>                    [key] => _slt_issues
>>                    [value] => 186
>>                )
>>            [7] => Array
>>                (
>>                    [key] => _slt_issues
>>                    [value] => 190
>>                )
>>            [8] => Array
>>                (
>>                    [key] => _slt_issues
>>                    [value] => 188
>>                )
>>            [9] => Array
>>                (
>>                    [key] => _slt_issues
>>                    [value] => 192
>>                )
>>        )
>> )
>>
>> This crashes the database in quite a severe way, and I've bothered my
>> sysadmin for a reboot one too many times now experimenting with it!
>>
>> Can anyone see anything obviously wrong? There's only ten or so
>> campaigns in the system, and about the same amount of issues. Is it
>> just the number of parts to the meta_query? Is it related to the fact
>> that _slt_issues may have multiple entires in the postmeta table for
>> the same campaign? Is there any feasible way of doing this query?
>>
>> Many thanks for any thoughts,
>>
>> Steve Taylor
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
>
>
>
> --
> Mike Van Winkle
> 708-289-3136
> mike at mikevanwinkle.com
> http://www.mikevanwinkle.com
> http://www.twitter.com/mpvanwinkle
> http://www.facebook.com/mpvanwinkle
>
>
> "All excellent things are as difficult as they are rare." -Spinoza
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list