I always thought, and searching on Google/SO seems to confirm, that these do the same:
SELECT ... FROM a
INNER JOIN b ON (a.foo = b.foo AND a.bar = b.bar)
should be equivalent to
SELECT ... FROM a
INNER JOIN b USING (foo, bar)
i.e. USING
is just syntactic sugar for the simple/general case where both tables have the same column names.
Now I'm observing different behavior with MariaDB on Debian 9 and 10, where 9 does what I expect and 10 doesn't.
Debian 9: mysqld Ver 10.1.26-MariaDB-0+deb9u1 for debian-linux-gnu on x86_64 (Debian 9.1)
Debian 10: mysqld Ver 10.3.17-MariaDB-0+deb10u1 for debian-linux-gnu on x86_64 (Debian 10)
Now I have a query that's supposed to list all constraints in all databases with their according update and delete rules.
This works on both:
SELECT a.CONSTRAINT_NAME, b.UPDATE_RULE, b.DELETE_RULE
FROM information_schema.KEY_COLUMN_USAGE a
INNER JOIN information_schema.REFERENTIAL_CONSTRAINTS b ON (
a.CONSTRAINT_CATALOG = b.CONSTRAINT_CATALOG
AND a.CONSTRAINT_SCHEMA = b.CONSTRAINT_SCHEMA
AND a.CONSTRAINT_NAME = b.CONSTRAINT_NAME
)
This returns an empty set on Debian 10 but works on 9:
SELECT a.CONSTRAINT_NAME, b.UPDATE_RULE, b.DELETE_RULE
FROM information_schema.KEY_COLUMN_USAGE a
INNER JOIN information_schema.REFERENTIAL_CONSTRAINTS b
USING (CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA, CONSTRAINT_NAME)
EXPLAIN
also looks identical for both queries:
+------+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------------------------------------------+
| 1 | SIMPLE | a | ALL | NULL | NULL | NULL | NULL | NULL | Open_full_table; Scanned all databases |
| 1 | SIMPLE | b | ALL | NULL | NULL | NULL | NULL | NULL | Using where; Open_full_table; Scanned all databases; Using join buffer (flat, BNL join) |
+------+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------------------------------------------+
What is going on here?