Php MYSQL对位置的多类搜索

Php MYSQL对位置的多类搜索,php,mysql,Php,Mysql,我有一个超过310K行的大型数据库。每行有以下字段: 国家 区域 城市 这是我的查询-我正在使用php pdo查询我的属性数据库: $sql = 'SELECT * FROM properties WHERE ( Country = "'.$searchString.'" OR Region = "'.$searchString.'" OR City = "'.$searchString.'") LIMIT 100'; $stmt =

我有一个超过310K行的大型数据库。每行有以下字段:

国家 区域 城市

这是我的查询-我正在使用php pdo查询我的属性数据库:

$sql =  'SELECT * FROM properties 
          WHERE ( Country = "'.$searchString.'" OR Region = "'.$searchString.'" 
                  OR City = "'.$searchString.'") LIMIT 100';
$stmt = $pdo->query($sql);
现在,虽然这一切都很好,但我知道这是混乱和资源密集型谁能解释给我一个更干净更快的方法做这件事也索引混淆我与mysql,我应该设置一个索引的三列和什么样的索引你会建议


非常感谢任何帮助或指针

索引不会有帮助,因为您已经编写了查询。您可以编写并添加有关propertiesCountry、Region、City的索引,并使用如下查询:

select p.*
from properties p
where country = @searchString
union all
select p.*
from properties p
where region = @searchString and country <> @searchString
union all
select p.*
from properties p
where city = @searchString and region <> @searchString and country <> @searchString;

这可能会有所帮助,但or查询通常返回的行太多,索引没有特别的帮助。

了解预处理语句以防止SQL注入Hi-jens,我实际上是在我的实时代码中使用预处理语句,很抱歉,我提到了我刚才在示例中遗漏了它们