WL#1074: Add Descending indexes support

Affects: Server-8.0   —   Status: Complete

Goal of this WL is to provide support for indexes in descending order. I.e
during forward index scan, values in such index are going in the descending
order, unlike ascending order which is supported by server now. There're two
reasons for this. First is often descending order is needed, but backward index
scan (which could be employed to execute queries in question) is noticeably
slower than forward index scan. Second reason is to be able to use indexes
instead of filesort for ORDER BY clause with mixed ASC/DESC sort key parts.

This WL will only support btree indexes. User would get an error when try to
create descending FTS / GIS index.

This WL should include:
*) Support in parser to allow to create indexes with DESC key parts. Parser
already allows DESC option, but simply ignores it
*) Enable SHOW commands to correctly report DESC key parts
*) Enable optimizer to detect when desc index could be used for ORDER BY
*) Enable optimizer to use indexes with mixed ASC/DESC keyparts when they
match ORDER BY clause
*) Indicate backward/forward index scans
*) Support for desc indexes in InnoDB (patch would be provided by InnoDB)
*) Support for range/loose index scans over indexes with DESC key parts

Limitations
-----------
*) An expected drawback that won't be covered by this WL is that when user has
two indexes, one ASC and another DESC over the same column, optimizer won't
necessary will be able to pick the right index. This is limitation of current
server architecture and planned to be addressed by WL#6179.
*) This WL won't add support for ROR scans over indexes with DESC key parts.
*) Backward range scans over indexes with mixed ASC/DESC key parts won't be
fully supported as they might require tricky reordering of ranges in order to
return record in proper order.
*) To limit the scope of the worklog, MIN/MAX optimization for queries without
GROUP BY is not performed for DESC keyparts.

Examples:
CREATE TABLE t1(
  a INT, b INT,
  KEY a_desc_b_asc (a DESC, b));

-- Should use (forward) index scan
SELECT * FROM t1 ORDER BY a DESC;

-- Should use backward index scan
SELECT * FROM t1 ORDER BY a ASC;

-- Should use (forward) index scan
SELECT * FROM t1 ORDER BY a DESC, b ASC;

-- Should use backward index scan
SELECT * FROM t1 ORDER BY a ASC, b DESC;

-- Should use filesort, not index
SELECT * FROM t1 ORDER BY a ASC, b ASC;

-- Should use filesort, not index
SELECT * FROM t1 ORDER BY a DESC, b DESC;


References
----------
Feature request: BUG#13375 Index with Desc sort feature

User Documentation
==================

* http://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-1.html
* http://dev.mysql.com/doc/refman/8.0/en/descending-indexes.html