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/osv/expression.py
leaf.add_join_context(next_model, model._inherits[next_model._name], 'id', model._inherits[next_model._name])
                push(leaf)
            elif left == 'id' and operator == 'child_of':
                ids2 = to_ids(right, model, context)
                dom = child_of_domain(left, ids2, model)
                for dom_leaf in reversed(dom):
                    new_leaf = create_substitution_leaf(leaf, dom_leaf, model)
                    push(new_leaf)
            elif not column and path[0] in MAGIC_COLUMNS:
                push_(leaf)
            elif not field:
                raise ValueError("Invalid field %r in leaf %r" % (left, str(leaf)))
            # 
            # 
            # 
            #    
            #      
            #    
            #      
            # 
            #    
            # 
            #    
            # 
            elif len(path) > 1 and column and column._type == 'many2one' and column._auto_join:
                # 
                leaf.add_join_context(comodel, path[0], 'id', path[0])
                push(create_substitution_leaf(leaf, (path[1], operator, right), comodel))
            elif len(path) > 1 and column and column._type == 'one2many' and column._auto_join:
                #