Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt PostgreSQL和QSqlQuery.bindValue()速度较慢_Qt_Postgresql - Fatal编程技术网

Qt PostgreSQL和QSqlQuery.bindValue()速度较慢

Qt PostgreSQL和QSqlQuery.bindValue()速度较慢,qt,postgresql,Qt,Postgresql,我有一个PostgreSQL数据库,一个包含150万条记录的表,代码如下: QString sql = "SELECT p.id, initcap(p.lname) lname, initcap(p.fname) fname, initcap(p.mname) mname, p.birthday, c.name as cname, p.enp " "FROM oms.persons p " "LEFT JOIN ref.countries c ON (p.citizenship

我有一个PostgreSQL数据库,一个包含150万条记录的表,代码如下:

QString sql = "SELECT p.id, initcap(p.lname) lname, initcap(p.fname) fname, initcap(p.mname) mname, p.birthday, c.name as cname, p.enp " "FROM oms.persons p " "LEFT JOIN ref.countries c ON (p.citizenship = c.code) " "WHERE p.lname LIKE :LNAME " "ORDER BY p.lname, p.fname, p.mname LIMIT 100"; QSqlQuery q; q.prepare(sql); q.bindValue(":LNAME", "TEST%"); q.exec(); QString sql=“选择p.id、initcap(p.lname)lname、initcap(p.fname)fname、initcap(p.mname)mname、p.birth、c.name作为cname、p.enp” “来自oms.p” “左连接参考国家c ON(p.公民身份=c.代码)” “其中p.lname类似于:lname” “按p.lname、p.fname、p.mname限额100下单”; qsqlq; q、 准备(sql); q、 bindValue(“:LNAME”,“TEST%”); q、 exec(); 这需要约1200毫秒,但如果我在没有bindValue()函数的情况下执行此查询并将:LNAME替换为“TEST%”,则只需要约30毫秒。 我应该怎么做来修复这个奇怪的QSqlQuery行为

规格: Qt 4.7.3 Windows Debian Linux上的PostgreSQL 8.4.8

答案很简单: “LIKE索引优化取决于在计划时看到一个恒定的LIKE模式,否则计划员不知道要生成什么indexscan参数。”