sphinx - 是否可以通过 Sphinx 比 MySQL 更快地搜索数字?
问题描述
我需要找到要查询的时间戳“最近或等于”的一行?
CREATE TABLE test ( date TIMESTAMP(6) UNIQUE, num INT(32) );
| 2018-07-02 05:50:33.084011 | 282 |
| 2018-07-02 05:50:33.084028 | 475 |
(40 M 这样的行...所有时间戳都是唯一的,因此该列是唯一索引)
狮身人面像.conf:
source src1
{
type = mysql
...
sql_query = SELECT * FROM test
}
# indexer...
Sphinx 3.0.3
...
indexing index 'test'...
collected 10000000 docs, 0.0 MB
在我的测试中,我找到要查询的最近时间戳:
$start = microtime(true);
$query = '2018-07-02 05:50:33.084011';
$connMySQL = new PDO('mysql:host=localhost;dbname=test','','');
$sql = "SELECT * FROM test WHERE date <= '$search' ORDER BY date DESC LIMIT 1";
$que = $connMySQL->query($sql);
$result = $que->fetchAll(PDO::FETCH_ASSOC);
print_r ($result);
echo 'Time MySQL:'.(microtime(true) - $start).' sec.';
$start = microtime(true);
$query = '2018-07-02 05:50:33.084028';
$connSphinxQL = new PDO('mysql:host=localhost;port=9306;dbname=test','root','');
$sql = "SELECT * FROM test WHERE date <= '$search' ORDER BY date DESC LIMIT 1";
$que = $connSphinxQL->query($sql);
$result = $que->fetchAll(PDO::FETCH_ASSOC);
print_r ($result);
echo 'Time Sphinx:'.(microtime(true) - $start).' sec.';
输出:
[date] => 2018-07-02 05:50:33.084011 [num] => 282 Time: 0.00193 sec.
[date] => 2018-07-02 05:50:33.084028 [num] => 475 Time: 0.00184 sec.
解决方案
推荐阅读
- javascript - Angular highcharts 在尝试绘制直方图时返回错误
- excel - 在 VBA 中添加 OLE 对象命令按钮会阻止它执行代码
- python - 绝对导入如何找到根目录?
- python - 查找所有不包含特定字符串的组合
- reactjs - 用于 AEM 6.1 和 6.2 版本的 AEM + React 集成
- css - 带系统网格的布局
- r - 根据第一个矩阵的行上的条件在 R 中形成一个新矩阵
- javascript - 在一系列时刻中查找 moment.js 对象?
- react-native - 带有两个按钮的平面列表单项
- sql - SQL:用于两级聚合的 INNER JOIN