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
return is_operator(self.leaf)
    def is_true_leaf(self):
        return self.leaf == TRUE_LEAF
    def is_false_leaf(self):
        return self.leaf == FALSE_LEAF
    def is_leaf(self, internal=False):
        return is_leaf(self.leaf, internal=internal)
    def normalize_leaf(self):
        self.leaf = normalize_leaf(self.leaf)
        return True
def create_substitution_leaf(leaf, new_elements, new_model=None, internal=False):
    """ From a leaf, create a new leaf (based on the new_elements tuple
        and new_model), that will have the same join context. Used to
        insert equivalent leafs in the processing stack. """
    if new_model is None:
        new_model = leaf.model
    new_join_context = [tuple(context) for context in leaf.join_context]
    new_leaf = ExtendedLeaf(new_elements, new_model, join_context=new_join_context, internal=internal)
    return new_leaf
class expression(object):
    """ Parse a domain expression
        Use a real polish notation
        Leafs are still in a ('foo', '=', 'bar') format
        For more info: http://christophe-simonis-at-tiny.blogspot.com/2008/08/new-new-domain-notation.html
    """
    def __init__(self, cr, uid, exp, table, context):