Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FLASH-504: Fix NULL order for DAG #281

Merged
merged 2 commits into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions dbms/src/Flash/Coprocessor/InterpreterDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,17 +524,16 @@ SortDescription InterpreterDAG::getSortDescription(Strings & order_column_names)
{
// construct SortDescription
SortDescription order_descr;
const tipb::TopN & topN = dag.getTopN();
order_descr.reserve(topN.order_by_size());
for (int i = 0; i < topN.order_by_size(); i++)
const tipb::TopN & topn = dag.getTopN();
order_descr.reserve(topn.order_by_size());
for (int i = 0; i < topn.order_by_size(); i++)
{
String name = order_column_names[i];
int direction = topN.order_by(i).desc() ? -1 : 1;
int direction = topn.order_by(i).desc() ? -1 : 1;
// MySQL/TiDB treats NULL as "minimum".
int nulls_direction = -1;
// todo get this information from DAGRequest
// currently use NULLS LAST
int nulls_direction = direction;
// todo get this information from DAGRequest
// currently use the defalut value
// currently use the default value
std::shared_ptr<Collator> collator;

order_descr.emplace_back(name, direction, nulls_direction, collator);
Expand Down
9 changes: 6 additions & 3 deletions tests/mutable-test/txn_dag/topn.test
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,25 @@
=> DBGInvoke __set_flush_threshold(1000000, 1000000)

# Data.
=> DBGInvoke __mock_tidb_table(default, test, 'col_1 String, col_2 Int64')
=> DBGInvoke __mock_tidb_table(default, test, 'col_1 Nullable(String), col_2 Nullable(Int64)')
=> DBGInvoke __refresh_schemas()
=> DBGInvoke __put_region(4, 0, 100, default, test)
=> DBGInvoke __raft_insert_row(default, test, 4, 50, 'test1', 666)
=> DBGInvoke __raft_insert_row(default, test, 4, 51, 'test2', 777)
=> DBGInvoke __raft_insert_row(default, test, 4, 52, NULL, NULL)

# DAG read by not specifying region id, order by col_2 limit 1.
=> DBGInvoke dag('select * from default.test order by col_2 limit 1')
=> DBGInvoke dag('select * from default.test order by col_2 limit 2')
┌─col_1─┬─col_2─┐
│ \N │ \N │
│ test1 │ 666 │
└───────┴───────┘

# Mock DAG read, where + topn.
=> DBGInvoke mock_dag('select col_2, col_1, col_2 from default.test where col_1 = \'test2\' or col_2 = 666 order by col_1 desc limit 1', 4)
=> DBGInvoke mock_dag('select col_2, col_1, col_2 from default.test where col_1 = \'test2\' or col_2 = 666 order by col_1 desc limit 2', 4)
┌─col_2─┬─col_1─┬─col_2─┐
│ 777 │ test2 │ 777 │
│ 666 │ test1 │ 666 │
└───────┴───────┴───────┘

# Clean up.
Expand Down