We observed that, while joining a table with a multi-column PK to itself:
- a join using all PK columns ran in .5s
- a join using all but one of the PK columns ran in 42-44s
Other, maybe extraneous information:
- all PK columns had btree indexes
- the column that we left out in the second case was a
BOOLEAN(actuallytinyint(1)) – so the result set was twice as large as in the first case - this was observed for both
inner joinandleft join - no non-PK columns were used in the joins
- running the query repeatedly did not result in a large decrease in execution time (maybe 2s)
Why was the difference in execution time so large?
There is a unique index placed on a (set of) PK columns. View the explain plan to verify, but it is likely that the index is only used when joining on all PK columns.