简体   繁体   English

如何使用php在数据库中的多列中更快地搜索

[英]how can search faster in more than column in database using php

If user type keyword in search box I want engine to search in more than 4 column this take long time if can suggest another solution to fast this search as it search in more than 80,000 rows如果用户在搜索框中输入关键字,我希望引擎在超过 4 列中搜索这需要很长时间,如果可以建议另一种解决方案来加快此搜索,因为它在 80,000 多行中搜索

$kay=$_GET['kay'];

<?php
$search_query = "select * from product where 
                             sku LIKE '%$kay%'
                            or mfr LIKE '%$kay%'
                             or manufacturer LIKE '%$kay%'
                               or LongDesc LIKE '%$kay%')";
?>

The kind of search you have specified -- an OR sequence of col LIKE '%value%' clauses -- is the very slowest way anyone can imagine to search a MySQL table.您指定的搜索类型—— col LIKE '%value%'子句的OR序列 - 是任何人都可以想象的最慢的搜索 MySQL 表的方式。 Why?为什么? The promiscuous wildcard search LIKE x where x starts with % can only be satisfied with a full scan.混杂通配符搜索LIKE x其中x%开头只能满足完整扫描。

Switch to FULLTEXT search.切换到FULLTEXT搜索。 You can read about it on the MySql documentation web site.您可以在 MySql 文档网站上阅读有关它的信息。

There was a recent article about an extension to PostgreSQL that exploits hundreds of GPU cores running in parallel to do searches;最近有一篇关于 PostgreSQL 扩展的文章,该扩展利用数百个并行运行的 GPU 内核进行搜索; that might help too.这也可能有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM