Commit 647dbc86 authored by Vincent Pelletier's avatar Vincent Pelletier

storage.database.mysqldb: Optimise getObject for most likely case.

loadBefore is more likely than other loads, as it is how repeatable-read is
implemented and the vast majority of accesses are scoped to a transaction.
So put it first in 3-branches "if" choosing between load/loadBefore/loadSerial
code paths.
next_serial is likely to not be found, because application will likely
operate on up-to-date objects. So a test is more efficient than a
try..except. Inline this test in return statement to avoid defining a local.
parent dba90afa
...@@ -297,10 +297,10 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -297,10 +297,10 @@ class MySQLDatabaseManager(DatabaseManager):
sql = ('SELECT tid, compression, data.hash, value, value_tid' sql = ('SELECT tid, compression, data.hash, value, value_tid'
' FROM obj LEFT JOIN data ON (obj.data_id = data.id)' ' FROM obj LEFT JOIN data ON (obj.data_id = data.id)'
' WHERE partition = %d AND oid = %d') % (partition, oid) ' WHERE partition = %d AND oid = %d') % (partition, oid)
if tid is not None: if before_tid is not None:
sql += ' AND tid = %d' % tid
elif before_tid is not None:
sql += ' AND tid < %d ORDER BY tid DESC LIMIT 1' % before_tid sql += ' AND tid < %d ORDER BY tid DESC LIMIT 1' % before_tid
elif tid is not None:
sql += ' AND tid = %d' % tid
else: else:
# XXX I want to express "HAVING tid = MAX(tid)", but # XXX I want to express "HAVING tid = MAX(tid)", but
# MySQL does not use an index for a HAVING clause! # MySQL does not use an index for a HAVING clause!
...@@ -312,11 +312,8 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -312,11 +312,8 @@ class MySQLDatabaseManager(DatabaseManager):
return None return None
r = q("SELECT tid FROM obj WHERE partition=%d AND oid=%d AND tid>%d" r = q("SELECT tid FROM obj WHERE partition=%d AND oid=%d AND tid>%d"
" ORDER BY tid LIMIT 1" % (partition, oid, serial)) " ORDER BY tid LIMIT 1" % (partition, oid, serial))
try: return (serial, r[0][0] if r else None, compression, checksum, data,
next_serial = r[0][0] value_serial)
except IndexError:
next_serial = None
return serial, next_serial, compression, checksum, data, value_serial
def doSetPartitionTable(self, ptid, cell_list, reset): def doSetPartitionTable(self, ptid, cell_list, reset):
offset_list = [] offset_list = []
......
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