用Sphinx比用MySQL搜索数字快吗?

用Sphinx比用MySQL搜索数字快吗?,sphinx,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 M这样的行…所有时间戳都是唯一的,因此此列是唯一的索引) sphinx.conf: source src1 { type = 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这样的行…所有时间戳都是唯一的,因此此列是唯一的索引)

sphinx.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.';

那么在MySql中,在一个字段中还是在十亿行中也有这样的内容?那么你的mysql查询是什么?在mysql中有10亿行。每行包含数百个字段。我现在只需要搜索每个字段。我仍然需要SQL查询本身。不清楚行是行,还是行中的单个单元格,带有newlinesadd索引,
altertable test ADD index(num)
应该允许在MYSQL中进行非常快速的查询
SELECT*fromtest-WHERE-num介于3和7之间
[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.