Fix a NULL-pointer dereference/crash that could occurs when a transitive WHERE
clause references a non-existent collating sequence. Ticket
e8d439c77685eca6.

Improved the cost estimation for an index scan which includes a WHERE clause
that can be partially or fully evaluated using columns in the index and without
having to do a table lookup. This fixes a performance regression that occurred
for some obscure queries following the ORDER BY LIMIT optimization introduced
in version 3.12.0.