Skip to content
This repository has been archived by the owner on Sep 3, 2019. It is now read-only.

merge all-shards results #21

Open
cholgyu-kang opened this issue Oct 23, 2017 · 0 comments
Open

merge all-shards results #21

cholgyu-kang opened this issue Oct 23, 2017 · 0 comments

Comments

@cholgyu-kang
Copy link
Contributor

problem

The ResultSet of all-shards query is just union-all of each shard ResultSet

  • aggregation query: ex) select count(*) from foo;
    expect> 1 row ResultSet
    current> multiple rows ResultSet

  • order-by query: ex) select * from foo order by 1;
    expect> fully ordered ResultSet
    current> partially ordered ResultSet for each shard result

suggestion

merge COUNT(), SUM(), MIN(), MAX(), AVG() query results

step 1

specify merging rule by API

  • RyeStatement.mergeRs(int operation, int result_col_index, int source_col_index)

  • RyeStatement.mergeRS(int operation, int result_col_index, int source_col_index, int collation)

    operation: SUM, MIN, MAX

  • RyeStatement.megeRs(int operation, int resultcol_index, int[] source_col_index)
    oeration: AVG

    source_col_index[0] : index of sum() result column
    source_col_index[1] : index of count() result column

  • value types
    SUM: bigint, numeric, double
    MIN, MAX: bigint, numeric, double, datetime, date, time, string

  • collation
    How to specify?
    Does driver collation rule have same result with server collation rule?
    https://docs.oracle.com/javase/6/docs/api/java/text/Collator.html

ex)
SELECT COUNT(*) FROM foo;
SELECT SUM(a) FROM foo;
--> RyeStatement.mergeRS(SUM, 1, 1);

SELECT MIN(a) FROM foo;
--> RyeStatement.mergeRs(MIN, 1, 1);
--> RyeStatement.mergeRs(MIN, 1, 1, collation);

SELECT SUM(a), COUNT(a) FROM foo;
--> RyeStatement.mergeRs(AVG, 1, {1,2})

merge order-by query results

step 1

specify sorting rule by API

  • RyeStatement.sortRs(SORT_SPEC[] spec_arr, int limit_offset, int limit_count)
    SORT_SPEC:
    int column_index'
    boolean isASCorder;
    int collation;

ex)
SELECT int_col, str_col, other_cols from foo ORDER by 1, 2 DESC limit 5
-->
sort_spec[0] = new SORT_SPEC(1, true, 0);
sort_spec[1] = new SORT_SPEC(2, false, collation);
RyeStatement.sortRS(sort_spec, 0, 5);

step 2

Driver itself set the merging or sorting API using server's parsing result.

connection property: merge_resultset=yes|no

  • merge_resultset=no : do not merge results
  • merge_resultset=yes : merge results. error if driver cannot convert parsing result to merging or sorting API

prepare result protocol changes

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant