[IMP] models.py: _auto_init: accelerate row existance check
authorChristophe Simonis <chs@odoo.com>
Tue, 12 Aug 2014 16:38:55 +0000 (18:38 +0200)
committerChristophe Simonis <chs@odoo.com>
Tue, 12 Aug 2014 16:38:55 +0000 (18:38 +0200)
Using `COUNT(1)` on big table can be slow. Use `min(id)` which use
pkey index to have a quicker response

openerp/models.py

index e8b531a..bbcee1f 100644 (file)
@@ -2474,8 +2474,8 @@ class BaseModel(object):
                 self._create_table(cr)
                 has_rows = False
             else:
-                cr.execute('SELECT COUNT(1) FROM "%s"' % (self._table,))
-                has_rows = cr.fetchone()[0]
+                cr.execute('SELECT min(id) FROM "%s"' % (self._table,))
+                has_rows = cr.fetchone()[0] is not None
 
             cr.commit()
             if self._parent_store: