Impacted versions:
8.0 and so on

Steps to reproduce:
create a many2many field in product.product such as:
`'company_ids':fields.many2many('res.company','res_company_product_rel','partner_id','company_ids',string=u'multi company''),`
and add a ir.rule for product.product with  domain such as
`['|',('company_id','=',False),('company_ids','in',[c.id for c in user.company_ids])]`
and import 10 thousand product.
then login with normal user(not super) and open the product.produt list view
it taks several minus to open

Current behavior:
when I search product.product
all product id have been hard coded in the sql 
lead to low performance.

Expected behavior:
not hard code produt id

Video/Screenshot link (optional):
in the sql below 10 thousand product id have been hard code in the position %s
AND ("product_product__product_tmpl_id"."company_id" IS NULL   OR  ("product_product"."id" in (%s)))

openerp/addons/base/tests/test_expression.py
self.assertTrue(set([p_a, p_b, p_aa, p_ab, p_ba]).issubset(set(partner_ids)),
            "_auto_join on: ('state_id.country_id.code', 'like', '..') incorrect result")
        
        self.assertEqual(len(self.query_list), 1,
            "_auto_join on: ('state_id.country_id.code', 'like', '..') should produce 1 query")
        sql_query = self.query_list[0].get_sql()
        self.assertIn('"res_partner"', sql_query[0],
            "_auto_join on: ('state_id.country_id.code', 'like', '..') query incorrect main table")
        self.assertIn('"res_country_state" as "res_partner__state_id"', sql_query[0],
            "_auto_join on: ('state_id.country_id.code', 'like', '..') query incorrect join")
        self.assertIn('"res_country" as "res_partner__state_id__country_id"', sql_query[0],
            "_auto_join on: ('state_id.country_id.code', 'like', '..') query incorrect join")
        expected = "%s::text like %s" % (unaccent('"res_partner__state_id__country_id"."code"'), unaccent('%s'))
        self.assertIn(expected, sql_query[1],
            "_auto_join on: ('state_id.country_id.code', 'like', '..') query incorrect where condition")
        
        self.assertIn('"res_partner"."state_id"="res_partner__state_id"."id"', sql_query[1],
            "_auto_join on: ('state_id.country_id.code', 'like', '..') query incorrect join condition")
        self.assertIn('"res_partner__state_id"."country_id"="res_partner__state_id__country_id"."id"', sql_query[1],
            "_auto_join on: ('state_id.country_id.code', 'like', '..') query incorrect join condition")
        self.assertEqual(['%' + name_test + '%'], sql_query[2],
            "_auto_join on: ('state_id.country_id.code', 'like', '..') query incorrect parameter")
        
        
        
        partner_child_ids_col._auto_join = True
        partner_bank_ids_col._auto_join = True
        partner_child_ids_col._domain = lambda self: ['!', ('name', '=', self._name)]
        partner_bank_ids_col._domain = [('acc_number', 'like', '1')]