Answer the question
In order to leave comments, you need to log in
What could be the reason for slow queries to sqlite?
I can not understand the reason for the hangup of more or less complex queries to the sqlite database.
There are about 10 thousand rows in two tables, most queries for selection, rare inserts and updates, one user works with the database.
On a normal working computer under Windows, all requests fly, no glitches were noticed.
When placing the same script and database on the server (vds under centos), simple queries work, you execute a query with a union and a couple of search conditions, the script hangs when fetching.
It's not about the script, for the test I reduced it to a minimum: connection, request, fetch and output to the stream.
It feels like the table is being locked and the script is waiting for the lock to be released, but given that there are no competitive requests and no load either on the server or on this particular script or database, this looks very strange.
I didn’t particularly come across sqlite databases, a search on the Internet suggests that the problem is frequent, but I didn’t see a specific solution or at least a reason.
Help with advice on what to see.
Code example:
$sql = 'select distinct "items".* from "items" left join "notes" on "notes"."item_id" = "items"."id" where ("notes"."name" like "%test%")';
$db = new SQLite3('path/to/db.sqlite');
$ret = $db->query($sql);
while ($row = $ret->fetchArray(SQLITE3_ASSOC)) {
echo var_export($row, true) . "<br>";
}
$db->close();
// пробовал делать и так:
$db = new PDO('sqlite:path/to/db.sqlite');
$ret = $db->query($sql);
foreach ($ret as $row) {
echo var_export($row, true) . "<br>";
}
$db = null;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question