我需要在mysql中搜索十亿条记录,这是一个很长的过程(现在可以了)。斯芬克斯能帮我吗?如何正确配置sphinx的搜索号码?是否应使用整数属性进行搜索(而不是字符串字段)?
我只需要获取时间戳“最接近或等于”的行来查询:
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米这样的排…所有时间戳都是唯一的,因此此列是唯一的索引,因此我不需要创建额外的索引。
狮身人面像形态:
source src1
{
type = mysql
...
sql_query = SELECT * FROM test
}
索引器…
Sphinx 3.0.3
...
indexing index 'test'...
collected 40000000 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);
$query = $connMySQL->query('reset query cache');
$connMySQL = null;
print_r ($result);
echo 'Time MySQL:'.(microtime(true) - $start).' sec.';
$start = microtime(true);
$query = '2018-07-02 05:50:33.084029';
$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);
$query = $connSphinxQL->query('reset query cache');
$connSphinxQL = null;
print_r ($result);
echo 'Time Sphinx:'.(microtime(true) - $start).' sec.';
输出:
[date] => 2018-07-02 05:50:33.084011 [num] => 282 Time MySQL: 0.00193 sec.
[date] => 2018-07-02 05:50:33.084028 [num] => 475 Time Sphinx: 0.00184 sec.
我建议看一些不同的RESUT,但是注意到在索引之前,我得到了相同的结果,所以我认为狮身人面像在MySQL中直接搜索是因为我的配置错误。
只问这里我发现:
no text search