Commit 3ddb6663 authored by Julien Muchembled's avatar Julien Muchembled

storage: a few "ORDER BY" were missing in backends

In practice, it may be only required for SQLite (because we don't force index)
on 'obj' (which as several indices).
parent 6ffafcbd
......@@ -475,6 +475,7 @@ class MySQLDatabaseManager(MVCCDatabaseManager):
def _getPackOrders(self, min_completed):
return self.query(
"SELECT * FROM pack WHERE tid >= %s AND tid %% %s IN (%s)"
" ORDER BY tid"
% (min_completed, self.np, ','.join(map(str, self._readable_set))))
def getPackedIDs(self, up_to_date=False):
......@@ -986,7 +987,7 @@ class MySQLDatabaseManager(MVCCDatabaseManager):
"SELECT `partition`, oid, MAX(tid) AS tid"
" FROM obj FORCE INDEX(PRIMARY)"
" WHERE `partition`=%s AND oid>=%s AND tid<=%s"
" GROUP BY oid LIMIT %s"
" GROUP BY oid ORDER BY oid LIMIT %s"
") AS t USING (`partition`, oid, tid)"
% (partition, u64(min_oid), u64(tid), length))
return None if len(r) < length else p64(r[-1][0] + self.np), \
......@@ -1005,17 +1006,18 @@ class MySQLDatabaseManager(MVCCDatabaseManager):
def _pack(self, offset, oid, tid, limit=None):
q = self.query
data_id_set = set()
sql = ("SELECT obj.oid,"
sql = ("SELECT obj.oid AS oid,"
" IF(data_id IS NULL OR n>1, tid + (data_id IS NULL), NULL)"
" FROM (SELECT COUNT(*) AS n, oid, MAX(tid) AS max_tid"
" FROM obj FORCE INDEX(PRIMARY)"
" WHERE `partition`=%s AND oid%s AND tid<=%s"
" GROUP BY oid%s) AS t"
" JOIN obj ON `partition`=%s AND t.oid=obj.oid AND tid=max_tid") % (
" JOIN obj ON `partition`=%s AND t.oid=obj.oid AND tid=max_tid"
" ORDER BY oid") % (
offset,
">=%s" % oid if limit else " IN (%s)" % ','.join(map(str, oid)),
tid,
" LIMIT %s" % limit if limit else "",
" ORDER BY oid LIMIT %s" % limit if limit else "",
offset)
oid = None
for oid, tid in q(sql):
......
......@@ -361,6 +361,7 @@ class SQLiteDatabaseManager(DatabaseManager):
def _getPackOrders(self, min_completed):
return self.query(
"SELECT * FROM pack WHERE tid >= ? AND tid %% %s IN (%s)"
" ORDER BY tid"
% (self.np, ','.join(map(str, self._readable_set))),
(min_completed,))
......@@ -778,7 +779,7 @@ class SQLiteDatabaseManager(DatabaseManager):
r = self.query("SELECT oid, data_id FROM obj JOIN ("
"SELECT `partition`, oid, MAX(tid) AS tid FROM obj"
" WHERE partition=? AND oid>=? AND tid<=?"
" GROUP BY oid LIMIT ?"
" GROUP BY oid ORDER BY oid LIMIT ?"
") AS t USING (`partition`, oid, tid)",
(partition, u64(min_oid), u64(tid), length)).fetchall()
return None if len(r) < length else p64(r[-1][0] + self.np), \
......@@ -808,7 +809,7 @@ class SQLiteDatabaseManager(DatabaseManager):
" WHERE partition=%s AND tid<=%s AND oid%s GROUP BY oid%s") % (
offset, tid,
">=%s" % oid if limit else " IN (%s)" % ','.join(map(str, oid)),
" LIMIT %s" % limit if limit else "")
" ORDER BY oid LIMIT %s" % limit if limit else "")
oid = None
for x, oid, max_tid in q(sql):
for x in q("SELECT tid + (data_id IS NULL) FROM obj"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment