Impacted versions:

8, 9, 10, master

Steps to reproduce:

Run `odoo shell --log-level=debug_sql` on a database where accounting is installed with demo data.

```
>>> AML = env['account.move.line']
>>> AML.search([('tax_ids.amount', '=', 15)])
```

You get the following trace of 4 sql statements:

The first one is ok:
```sql
SELECT "account_tax".id FROM "account_tax" WHERE (("account_tax"."active" = %s)  AND  ("account_tax"."amount" = %s)) ORDER BY "account_tax"."sequence"  
```

The second one can be improved and is discussed in https://github.com/odoo/odoo/pull/16066, it's not the point of this issue.
```sql
SELECT "account_move_line_id" FROM "account_move_line_account_tax_rel" WHERE "account_tax_id" IN %s
```

Then it does the same query twice with apparently no good reason (at least none I understand).
```sql
SELECT "account_move_line".id FROM "account_move_line" WHERE ("account_move_line"."id" in (%s)) ORDER BY "account_move_line"."date" DESC,"account_move_line"."id" DESC 
SELECT "account_move_line".id FROM "account_move_line" WHERE ("account_move_line"."id" in (%s)) ORDER BY "account_move_line"."date" DESC,"account_move_line"."id" DESC 
```

The problem has its source [here](https://github.com/odoo/odoo/blob/b8ce0db8e105ed3c9ab4aefe8bce5028764694f4/odoo/osv/expression.py#L879): at first glance I'd say lines 879 and 880 could be replaced with

```leaf.leaf = (path[0], 'in', right_ids)```
alias[:ALIAS_PREFIX_LENGTH], alias_hash)
    return '%s' % alias, '%s as %s' % (_quote(joined_tables[-1][0]), _quote(alias))
def get_alias_from_query(from_query):
    """ :param string from_query: is something like :
        - '"res_partner"' OR
        - '"res_partner" as "res_users__partner_id"''
    """
    from_splitted = from_query.split(' as ')
    if len(from_splitted) > 1:
        return from_splitted[0].replace('"', ''), from_splitted[1].replace('"', '')
    else:
        return from_splitted[0].replace('"', ''), from_splitted[0].replace('"', '')
def normalize_leaf(element):
    """ Change a term's operator to some canonical form, simplifying later
        processing. """
    if not is_leaf(element):
        return element
    left, operator, right = element
    original = operator
    operator = operator.lower()
    if operator == '<>':
        operator = '!='
    if isinstance(right, bool) and operator in ('in', 'not in'):
        _logger.warning("The  '%s' should use the '=' or '!=' operator." % ((left, original, right),))
        operator = '=' if operator == 'in' else '!='
    if isinstance(right, (list, tuple)) and operator in ('=', '!='):
        _logger.warning("The  '%s' should use the 'in' or 'not in' operator." % ((left, original, right),))
        operator = 'in' if operator == '=' else 'not in'
    return left, operator, right
def is_operator(element):