WL#4443: Remove scalability problem with many locks and external locks on partitioned tables with many partitions

Affects: Server-Prototype Only   —   Status: Complete

Since tables are locked before any preparation and optimizing is done, it is not
possible to prune partition locks in the optimizing phase.

This leads to bad performance and unnecessary work (all partitions are locked
for each and every query, if not explicit pruning, WL#5217, is used).

Therefore if we delay the locking until after prune_partitions is called we can
skip locking of pruned/non used partitions.

This can be done by also call prune_partitions in JOIN::prepare() to prune on
constants (non constants and subqueries cannot be locked pruned).

We must also enforce that nothing in the prepare phase rely on locked tables.


One side effect of this worklog will be shorter table locks too, since the
prepare phase will be done before
locking all tables. This may increase the overall performance.

This will fix BUG#37252.

Since locking is the major problem for many partitions, this worklog will not
try to delay any open calls (since open tables are cached). That will be
wl#3513, which may need refactoring of the table cache.