[FIX] ir_translation Indexes Corrected using hash indexes
authorAnup (OpenERP) <ach@tinyerp.com>
Tue, 21 Sep 2010 12:38:20 +0000 (18:08 +0530)
committerAnup (OpenERP) <ach@tinyerp.com>
Tue, 21 Sep 2010 12:38:20 +0000 (18:08 +0530)
lp bug: https://launchpad.net/bugs/544437 fixed

bzr revid: ach@tinyerp.com-20100921123820-4atqd71ex9ieqk1y

bin/addons/base/ir/ir_translation.py

index f683a51..ed05522 100644 (file)
@@ -65,21 +65,27 @@ class ir_translation(osv.osv):
 
     def _auto_init(self, cr, context={}):
         super(ir_translation, self)._auto_init(cr, context)
+        #Delete the existing indexes in the system if any.
         cr.execute('SELECT indexname FROM pg_indexes WHERE indexname = %s', ('ir_translation_ltns',))
-        if not cr.fetchone():
-            cr.execute('CREATE INDEX ir_translation_ltns ON ir_translation (lang, type, name, src)')
+        if cr.fetchone():
+            cr.execute('DROP INDEX ir_translation_ltns')
             cr.commit()
-
+        
+        cr.execute('SELECT indexname FROM pg_indexes WHERE indexname = %s', ('ir_translation_lts',))
+        if cr.fetchone():
+            cr.execute('DROP INDEX ir_translation_lts')
+            cr.commit()
+            
         cr.execute('SELECT indexname FROM pg_indexes WHERE indexname = %s', ('ir_translation_ltn',))
         if not cr.fetchone():
-            cr.execute('CREATE INDEX ir_translation_ltn ON ir_translation (lang, type, name)')
+            cr.execute('CREATE INDEX ir_translation_ltn ON ir_translation (name, lang, type)')
             cr.commit()
-
-        cr.execute('SELECT indexname FROM pg_indexes WHERE indexname = %s', ('ir_translation_lts',))
+        # There is a size limit on btree indexed values so we can't index src column with normal btree.
+        cr.execute('SELECT indexname FROM pg_indexes WHERE indexname = %s', ('ir_translation_src_hash_idx',))
         if not cr.fetchone():
-            cr.execute('CREATE INDEX ir_translation_lts ON ir_translation (lang, type, src)')
+            cr.execute('CREATE INDEX ir_translation_src_hash_idx ON ir_translation using hash (src)')
             cr.commit()
-
+            
     @tools.cache(skiparg=3, multi='ids')
     def _get_ids(self, cr, uid, name, tt, lang, ids):
         translations = dict.fromkeys(ids, False)