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
instr = unaccent('%s')
                    if sql_operator == 'in':
                        # 
                        instr = '(%s)' % ', '.join(['%s'] * len(right))
                    subselect = """WITH temp_irt_current (id, name) as (
                            SELECT ct.id, coalesce(it.value,ct.{quote_left})
                            FROM {current_table} ct 
                            LEFT JOIN ir_translation it ON (it.name = %s and 
                                        it.lang = %s and 
                                        it.type = %s and 
                                        it.res_id = ct.id and 
                                        it.value != '')
                            ) 
                            SELECT id FROM temp_irt_current WHERE {name} {operator} {right} order by name
                            """.format(current_table=model._table, quote_left=_quote(left), name=unaccent('name'), 
                                       operator=sql_operator, right=instr)
                    params = (
                        model._name + ',' + left,
                        context.get('lang') or 'en_US',
                        'model',
                        right,
                    )
                    push(create_substitution_leaf(leaf, ('id', inselect_operator, (subselect, params)), model, internal=True))
                else:
                    push_(leaf)
        # 
        # 
        # 
        # 
        joins = set()