**Describe what's wrong**

Selecting from a Buffer table with ORDER BY <col> DESC clause returns wrong rows, and the returned rows are not ordered.

**Does it reproduce on recent release?**

Tested version: 22.7.2.15

**How to reproduce**

* Which ClickHouse server version to use
22.7.2.15
* `CREATE TABLE` statements for all tables involved

        CREATE TABLE mydb.mytable_stored
        (
            `a` UInt8
        )
        ENGINE = MergeTree
        ORDER BY a;

        CREATE TABLE mydb.mytable
        (
            `a` UInt8
        )
        ENGINE = Buffer('mydb', 'mytable_stored', 4, 600, 3600, 10, 100, 10000, 10000000);

* Sample data for all these tables
Note: rows must be inserted one-by-one:

        INSERT INTO mydb.mytable VALUES (0);
        INSERT INTO mydb.mytable VALUES (1);
        INSERT INTO mydb.mytable VALUES (2);
        INSERT INTO mydb.mytable VALUES (3);
        INSERT INTO mydb.mytable VALUES (4);
        INSERT INTO mydb.mytable VALUES (5);
        INSERT INTO mydb.mytable VALUES (6);
        INSERT INTO mydb.mytable VALUES (7);
        INSERT INTO mydb.mytable VALUES (8);
        INSERT INTO mydb.mytable VALUES (9);

* Queries to run that lead to unexpected result

        SELECT a FROM mydb.mytable ORDER BY a DESC LIMIT 5;
        ┌─a─┐
        │ 3 │
        │ 7 │
        └───┘
        ┌─a─┐
        │ 2 │
        │ 6 │
        └───┘
        ┌─a─┐
        │ 1 │
        └───┘
        5 rows in set. Elapsed: 0.007 sec.

(Interestingly, ascending order *seems* to work, did not test it thoroughly though.)

**Expected behavior**

Get the results in descending order, ie. `9, 8, 7, 6, 5`.

**Additional context**

Selecting the maximal value works:

        SELECT max(a) FROM mydb.mytable;
        ┌─max(a)─┐
        │      9 │
        └────────┘
        1 row in set. Elapsed: 0.007 sec.

After the rows are flushed to the backing MergeTree table, the results are good.

        OPTIMIZE TABLE mydb.mytable;
        SELECT a FROM mydb.mytable ORDER BY a DESC LIMIT 5;
        ┌─a─┐
        │ 9 │
        │ 8 │
        │ 7 │
        │ 6 │
        │ 5 │
        └───┘
        5 rows in set. Elapsed: 0.008 sec. 


time_t time_passed = current_time - min_first_write_time;
    size_t min = std::max<ssize_t>(min_thresholds.time - time_passed, 1);
    size_t max = std::max<ssize_t>(max_thresholds.time - time_passed, 1);
    size_t flush = std::max<ssize_t>(flush_thresholds.time - time_passed, 1);
    flush_handle->scheduleAfter(std::min({min, max, flush}) * 1000);
}
void StorageBuffer::checkAlterIsPossible(const AlterCommands & commands, ContextPtr local_context) const
{
    auto name_deps = getDependentViewsByColumn(local_context);
    for (const auto & command : commands)
    {
        if (command.type != AlterCommand::Type::ADD_COLUMN && command.type != AlterCommand::Type::MODIFY_COLUMN
            && command.type != AlterCommand::Type::DROP_COLUMN && command.type != AlterCommand::Type::COMMENT_COLUMN
            && command.type != AlterCommand::Type::COMMENT_TABLE)
            throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Alter of type '{}' is not supported by storage {}",
                command.type, getName());
        if (command.type == AlterCommand::Type::DROP_COLUMN && !command.clear)
        {
            const auto & deps_mv = name_deps[command.column_name];
            if (!deps_mv.empty())
            {
                throw Exception(
                    "Trying to ALTER DROP column " + backQuoteIfNeed(command.column_name) + " which is referenced by materialized view "
                        + toString(deps_mv),
                    ErrorCodes::ALTER_OF_COLUMN_IS_FORBIDDEN);
            }
        }
    }
}
std::optional<UInt64> StorageBuffer::totalRows(const Settings & settings) const