Php 使用pdo_sqlite时,SQL查询中的“LIKE”运算符非常慢

Php 使用pdo_sqlite时,SQL查询中的“LIKE”运算符非常慢,php,sql,sqlite,pdo,sql-like,Php,Sql,Sqlite,Pdo,Sql Like,我发现,在pdo_sqlite PHP5.3或PHP5.4中,“SELECT”SQL查询中的“LIKE”操作符非常慢。 在sqlite3二进制文件中输入相同的查询要快得多 示例代码: <?php $bdd = new PDO('sqlite:./chaines_centre.db'); $reponse = $bdd->prepare("select DateMonteeAuPlan, Debut, Fin, Statut from ReportJobs w

我发现,在pdo_sqlite PHP5.3或PHP5.4中,“SELECT”SQL查询中的“LIKE”操作符非常慢。 在sqlite3二进制文件中输入相同的查询要快得多

示例代码:

<?php
    $bdd = new PDO('sqlite:./chaines_centre.db');
    $reponse = $bdd->prepare("select DateMonteeAuPlan, Debut, Fin, Statut from ReportJobs where NomJob = ? and NomChaine like 'DCLC257__' order by DateMonteeAuPlan DESC limit 20;");
    $reponse->execute($_GET['job']);
    while ($donnees = $reponse->fetch())
    {
        // whatever...
    }
    $reponse->closeCursor();
?>
通过删除LIKE运算符或order By DATEAUPLAN,查询将在预期时间内执行。。。
真奇怪。o_o

您有没有在同一个脚本中一个接一个地运行PDO vs二进制文件?如果您这样做了,那么使用binary获得更好的结果将是正常的,因为PDO在缓存为空时运行,因此它会命中光盘,而binary从RAM获取数据

对于第二个脚本,情况肯定是这样的:第一个查询获得1.3秒以上的时间,因为它还读取数据,而其余的则从RAM获取数据


有关详细信息,请参阅。

NomChaine是否已编制索引?如果没有,为什么这只会影响PDO?我编辑了我的第一篇文章,这个问题与运算符无关。我在这个表上没有任何索引,但这似乎不是问题。
<?php
$bdd = new PDO('sqlite:./chaines_centre.db');


$time_start = microtime(true);
$reponse = $bdd->query("select DateMonteeAuPlan, Debut, Fin, Statut from ReportJobs where NomJob = 'NSAVBASE' and NomChaine like 'DCLC257%' order by DateMonteeAuPlan DESC limit 20;");
$time_end = microtime(true);

$time = $time_end - $time_start;
echo "Situation 1 : $time second(s)<br><br>";
// Output : 1.3900790214539 second(s)


$time_start = microtime(true);
$reponse = $bdd->query("select DateMonteeAuPlan, Debut, Fin, Statut from ReportJobs where NomJob = 'NSAVBASE' and NomChaine like 'DCLC257%' limit 20;");
$time_end = microtime(true);

$time = $time_end - $time_start;
echo "Situation 2 : $time second(s)<br><br>";
// Output : 0.0030009746551514 seconde(s)


$time_start = microtime(true);
$reponse = $bdd->query("select DateMonteeAuPlan, Debut, Fin, Statut from ReportJobs where NomJob = 'NSAVBASE' and NomChaine = 'DCLC25736' order by DateMonteeAuPlan DESC limit 20;");
$time_end = microtime(true);

$time = $time_end - $time_start;
echo "Situation 3 : $time second(s)<br><br>";
// Output : 0 seconde(s)
?>