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
fct_domain = []
                else:
                    fct_domain = column.search(cr, uid, model, left, [leaf.leaf], context=context)
                if not fct_domain:
                    leaf.leaf = TRUE_LEAF
                    push(leaf)
                else:
                    # 
                    # 
                    for domain_element in reversed(fct_domain):
                        push(create_substitution_leaf(leaf, domain_element, model))
                    # 
                    # 
            # 
            # 
            # 
            # 
            elif column._type == 'one2many' and operator == 'child_of':
                ids2 = to_ids(right, comodel, context)
                if column._obj != model._name:
                    dom = child_of_domain(left, ids2, comodel, prefix=column._obj)
                else:
                    dom = child_of_domain('id', ids2, model, parent=left)
                for dom_leaf in reversed(dom):
                    push(create_substitution_leaf(leaf, dom_leaf, model))
            elif column._type == 'one2many':
                call_null = True
                if right is not False:
                    if isinstance(right, basestring):
                        ids2 = [x[0] for x in comodel.name_search(cr, uid, right, [], operator, context=context, limit=None)]