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)))

else:
                                res_ids = right
                        if not res_ids:
                            if operator in ['like', 'ilike', 'in', '=']:
                                #n
                                call_null_m2m = False
                                push(create_substitution_leaf(leaf, FALSE_LEAF, model))
                            else:
                                operator = 'in'  # 
                        else:
                            call_null_m2m = False
                            subop = 'not inselect' if operator in NEGATIVE_TERM_OPERATORS else 'inselect'
                            subquery = 'SELECT "%s" FROM "%s" WHERE "%s" IN %%s' % (rel_id1, rel_table, rel_id2)
                            # 
                            subquery = cr.mogrify(subquery, [tuple(filter(None, res_ids))])
                            push(create_substitution_leaf(leaf, ('id', subop, (subquery, [])), internal=True))
                    if call_null_m2m:
                        m2m_op = 'in' if operator in NEGATIVE_TERM_OPERATORS else 'not in'
                        push(create_substitution_leaf(leaf, ('id', m2m_op, select_distinct_from_where_not_null(cr, rel_id1, rel_table)), model))
            elif column._type == 'many2one':
                if 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))
                else:
                    def _get_expression(comodel, cr, uid, left, right, operator, context=None):