Note that there are some explanatory texts on larger screens.

plurals
  1. POVery slow performance in getting the results of QSqlQuery
    text
    copied!<p>I am seeing inexplicably slow behavior from a sqlite database in Qt. The query in the code below, when executed from the sqlite command line utility on the same database, completes instantaneously.</p> <pre><code>qDebug() &lt;&lt; "Beginning" &lt;&lt; QDateTime::currentDateTime ().toString(Qt::ISODate); QSqlQuery q(QSqlDatabase::database(mFilename)); q.prepare( "select TextFormIndex.Id from TextFormIndex,MorphologicalAnalysisMembers,Allomorph on TextFormId=Id and AllomorphId=Allomorph._id where LexicalEntryId=:Id;" ); q.bindValue(":Id", id); QSet&lt;qlonglong&gt; textFormIds; if( !q.exec() ) { qWarning() &lt;&lt; "DatabaseAdapter::lexicalEntryTextForms" &lt;&lt; q.lastError().text() &lt;&lt; q.executedQuery(); return textFormIds; } qDebug() &lt;&lt; "Before while" &lt;&lt; QDateTime::currentDateTime ().toString(Qt::ISODate); int nResults = 0; while( q.next() ) { qDebug() &lt;&lt; nResults++ &lt;&lt; QDateTime::currentDateTime().toString(Qt::ISODate); q.value(0).toLongLong(); } qDebug() &lt;&lt; "After while"; </code></pre> <p>The debug output form this code is:</p> <pre><code>Beginning "2013-02-04T20:31:24" Before while "2013-02-04T20:31:26" 0 "2013-02-04T20:31:26" 1 "2013-02-04T20:31:27" 2 "2013-02-04T20:31:41" 3 "2013-02-04T20:31:44" After while </code></pre> <p>Somehow the third call is taking fourteen seconds.</p> <p>This is a single method in a good-sized project. None of my queries have been executing slowly until this one.</p> <pre><code>create table if not exists TextFormIndex ( TextName text, LineNumber integer, Id integer ); create table if not exists MorphologicalAnalysisMembers ( _id integer primary key autoincrement, TextFormId integer, AllomorphId integer, AllomorphOrder integer ); create table if not exists Allomorph ( _id integer primary key autoincrement, LexicalEntryId integer, WritingSystem integer, Form text ); </code></pre> <p>MorphologicalAnalysisMembers.AllomorphId corresponds to Allomorph._id. TextFormIndex.Id corresponds to MorphologicalAnalysisMembers.TextFormId.</p> <p>MorphologicalAnalysisMembers has 4082 rows TextFormIndex has 17710 rows Allomorph has 1660 rows</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload