【发布时间】:2021-07-23 04:12:19
【问题描述】:
我有这个查询,当我减少过滤器时它变得很快,但是当我增加过滤器时它变得太慢,请我需要使用所有这些过滤器使其快速。 由于我的详细信息很清楚,但我正在写一些行,因为它不允许我发布我的问题
$args = array('post_type' => 'property', 'posts_per_page' => 1,'order' => 'asc',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'facilityname',
'value' => $_GET['keyword'],
'compare' => 'LIKE'
),
array(
'key' => 'city',
'value' => $_GET['city'],
'compare' => 'LIKE'
),
array(
'key' => 'facilitytype',
'value' => $_GET['facilitytype'],
'compare' => 'LIKE'
),
array(
'key' => 'hospitaltype',
'value' => $_GET['hospitaltype'],
'compare' => 'LIKE'
),
array(
'key' => 'state',
'value' => $_GET['state'],
'compare' => 'LIKE'
),
array(
'key' => 'idn',
'value' => $_GET['idn'],
'compare' => 'LIKE'
),
array(
'key' => 'gpoaffiliations',
'value' => $_GET['gpoaffiliations'],
'compare' => 'LIKE'
),
array(
'key' => 'bedcounttotal',
'value' => array($_GET['min-bedcounttotal'], $_GET['max-bedcounttotal']),
'compare' => 'BETWEEN',
'type' => 'NUMERIC'
),
array(
'key' => 'zipcode',
'value' => array($_GET['minzipcode'], $_GET['maxzipcode']),
'compare' => 'BETWEEN',
'type' => 'NUMERIC'
),
array(
'key' => 'operatingroomcount',
'value' => array($_GET['minoperatingroomcount'], $_GET['maxoperatingroomcount']),
'compare' => 'BETWEEN',
'type' => 'NUMERIC'
),
)
);
【问题讨论】:
-
不幸的是,我没有看到在一个查询中进行这么多
LIKE比较的情况可能会很快。根据您正在搜索的数据集的大小,您可能希望为用户提供一组预定义的选项,用于大多数输入,然后使用 = 比较而不是 LIKE。 -
感谢您的评论,那么我应该用什么来代替“LIKE”?
-
而不是
LIKE,只需使用=。我认为state、hospitaltype和facilitytype绝对可以切换到那个,除非你让人们搜索isconsi或其他东西。您还可以从$wp_query获取实际的 SQL 查询,并尝试使用manually optimize it 或保存数据的表 -
请提供(1)生成的SQL,和(2)SHOW CREATE TABLE。
-
搜索大约 21k 个帖子让我可以编辑我的问题
标签: php mysql wordpress performance