Earlier quoted context omitted.
...Except the number of query plans is O(n!), where n is the number of joins. MongoDB's query optimizer actually works like this, which is only tractable because it doesn't support joins.
I was about to write "Ummm...column order doesn't matter, so it's O(2^n)", but then I did some thinking and a bit of googling, and I guess it does. Yeah, O(n!). Although, in practice, most tables would only have a relatively small number of columns upon which you'd want to consider building an index (usually on columns (often IDs) that you'd use to join to other tables), so that'd cut it down to O(m!) where m Hmmmm,…
This is actually pretty much how a basic relational query optimizer works in practice.