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

[opt](hive)opt select count(*) stmt push down agg on parquet in hive . #22115

Merged
merged 10 commits into from
Jul 28, 2023

Conversation

hubgeter
Copy link
Contributor

@hubgeter hubgeter commented Jul 22, 2023

Proposed changes

after pr : #14827 and #12803

Optimization "select count(*) from table" stmtement , push down "count" type to be .

support file type : parquet ,orc in hive .

  1. 4kfiles , 60kwline num

    before: 1 min 37.70 sec

    after: 50.18 sec

  2. 50files , 60kwline num

    before: 1.12 sec

    after: 0.82 sec

Further comments

If this is a relatively large or complex change, kick off the discussion at [email protected] by explaining why you chose the solution you did and what alternatives you considered, etc...

@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

//fill one column is enough
auto cols = block->mutate_columns();
for (auto& col : cols) {
col->resize(rows);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rows maybe too large for the resize?
Normally, a block only return 4096 rows. But here you may return unlimited rows.
I think it should be splitted in batch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea

@@ -31,6 +31,12 @@ class Block;
class GenericReader {
public:
virtual Status get_next_block(Block* block, size_t* read_rows, bool* eof) = 0;

virtual Status get_next_block(Block* block, size_t* read_rows, bool* eof,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about merge these 2 methods?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea , but i need append parameter TPushAggOp::type push_down_agg_type_opt to all get_next_block functions


if (_parent->push_down_agg_type_opt != TPushAggOp::type ::NONE) {
//Prevent FE misjudging the "select count/min/max ..." statement
if (Status::OK() == _cur_reader->get_next_block(_src_block_ptr, &read_rows,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if here _cur_reader->get_next_block return error, it will go on calling another get_next_block(), just like a retry?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest that we should make sure FE give the right plan, and here we just use if...else.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because FE needs to add a lot of redundant code to determine the file type in order to obtain the correct plan 。

15: optional set<i32> output_column_unique_ids
16: optional list<i32> distribute_column_ids
17: optional i32 schema_version
12: optional bool use_topn_opt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't modify the origin structure of thrift, or it will cause problem when upgrading.
You can mark the old push_down_agg_type_opt as Deprecated, and make some compatibility
when visiting this field

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea

@@ -351,6 +351,9 @@ class VScanNode : public ExecNode, public RuntimeFilterConsumer {
std::unordered_map<std::string, int> _colname_to_slot_id;
std::vector<int> _col_distribute_ids;

public:
TPushAggOp::type push_down_agg_type_opt;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better not using public to define a field

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

if (pushDownAggNoGroupingOp != null) {
msg.olap_scan_node.setPushDownAggTypeOpt(pushDownAggNoGroupingOp);
if (pushDownAggNoGroupingOp != TPushAggOp.NONE) {
msg.setPushDownAggTypeOpt(pushDownAggNoGroupingOp);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can ALWAYS set this field

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

}
textParams.setColumnSeparator(hmsTable.getRemoteTable().getSd().getSerdeInfo().getParameters()
.getOrDefault(PROP_FIELD_DELIMITER, DEFAULT_FIELD_DELIMITER));
textParams.setLineDelimiter(DEFAULT_LINE_DELIMITER);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why changing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a mistake 。There's no need to change here。

}

String aggFunctionName = aggExpr.getFnName().getFunction();
if (aggFunctionName.equalsIgnoreCase("COUNT") && fileFormatType == TFileFormatType.FORMAT_PARQUET) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to implement orc too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

}

@Override
public boolean pushDownAggNoGroupingCheckCol(FunctionCallExpr aggExpr, Column col) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For external table, always return false.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when you use select count(*)statement ,pushDownAggNoGroupingCheckCol will not be executed .
if you use select count(a) statement , pushDownAggNoGroupingCheckCol will check col a.

@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

1 similar comment
@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

return aggregate.withChildren(ImmutableList.of(
new PhysicalStorageLayerAggregate(physicalOlapScan, mergeOp)
));
return canNotPush;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you want

PhysicalOlapScan physicalScan;
    if (logicalScan instanceof LogicalOlapScan) {
             physicalScan = (PhysicalOlapScan) new LogicalOlapScanToPhysicalOlapScan()
                    .build()
                    .transform((LogicalOlapScan) logicalScan, cascadesContext)
                    .get(0);

    } else if (logicalScan instanceof LogicalFileScan) {
            physicalScan = (PhysicalFileScan) new LogicalFileScanToPhysicalFileScan()
                    .build()
                    .transform((LogicalFileScan) logicalScan, cascadesContext)
                    .get(0);            
    } else {
        return canNotPush;
    }

    if (project != null) {
        return aggregate.withChildren(ImmutableList.of(
                    project.withChildren(
                    ImmutableList.of(new PhysicalStorageLayerAggregate(physicalScan, mergeOp)))
            ));
    } else {
            return aggregate.withChildren(ImmutableList.of(
                new PhysicalStorageLayerAggregate(physicalScan, mergeOp)
            ));
    }

you will get this:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile (default-compile) on project fe-core: Compilation failure: Compilation failure: 
[ERROR] /mnt/datadisk1/changyuwei/doris2/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/AggregateStrategies.java:[345,72] incompatible types: org.apache.doris.nereids.trees.plans.physical.PhysicalRelation cannot be converted to org.apache.doris.nereids.trees.plans.physical.PhysicalCatalogRelation
[ERROR] /mnt/datadisk1/changyuwei/doris2/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/AggregateStrategies.java:[349,51] incompatible types: org.apache.doris.nereids.trees.plans.physical.PhysicalRelation cannot be converted to org.apache.doris.nereids.trees.plans.physical.PhysicalCatalogRelation

😭😤😭

col->resize(rows);
}

*read_rows = rows;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate with line 1388


if (tnode.__isset.push_down_agg_type_opt) {
_push_down_agg_type = tnode.push_down_agg_type_opt;
} else if (tnode.olap_scan_node.__isset.push_down_agg_type_opt) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add some comment in code to explain these compatibility work

@morningman
Copy link
Contributor

Please add some test cases

@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

1 similar comment
@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

1 similar comment
@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

morningman
morningman previously approved these changes Jul 27, 2023
Copy link
Contributor

@morningman morningman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@github-actions github-actions bot added the approved Indicates a PR has been approved by one committer. label Jul 27, 2023
@github-actions
Copy link
Contributor

PR approved by at least one committer and no changes requested.

@github-actions
Copy link
Contributor

PR approved by anyone and no changes requested.

924060929
924060929 previously approved these changes Jul 27, 2023
@morningman
Copy link
Contributor

run buildall

@hubgeter hubgeter dismissed stale reviews from 924060929 and morningman via 0d9e4bf July 28, 2023 03:16
@github-actions github-actions bot removed the approved Indicates a PR has been approved by one committer. label Jul 28, 2023
@hubgeter
Copy link
Contributor Author

run buildall

@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@hello-stephen
Copy link
Contributor

(From new machine)TeamCity pipeline, clickbench performance test result:
the sum of best hot time: 46.36 seconds
stream load tsv: 505 seconds loaded 74807831229 Bytes, about 141 MB/s
stream load json: 20 seconds loaded 2358488459 Bytes, about 112 MB/s
stream load orc: 64 seconds loaded 1101869774 Bytes, about 16 MB/s
stream load parquet: 30 seconds loaded 861443392 Bytes, about 27 MB/s
insert into select: 29.1 seconds inserted 10000000 Rows, about 343K ops/s
storage size: 17156006903 Bytes

Copy link
Contributor

@morningman morningman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@github-actions github-actions bot added the approved Indicates a PR has been approved by one committer. label Jul 28, 2023
@github-actions
Copy link
Contributor

PR approved by at least one committer and no changes requested.

@hubgeter hubgeter requested a review from 924060929 July 28, 2023 09:51
Copy link
Contributor

@kaka11chen kaka11chen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@morningman morningman merged commit ae8a263 into apache:master Jul 28, 2023
xiaokang pushed a commit to xiaokang/doris that referenced this pull request Aug 9, 2023
apache#22115)

Optimization "select count(*) from table" stmtement , push down "count" type to BE.
support file type : parquet ,orc in hive .

1. 4kfiles , 60kwline num
    before:  1 min 37.70 sec
    after:   50.18 sec

2. 50files , 60kwline num
    before: 1.12 sec
    after: 0.82 sec
morningman pushed a commit to morningman/doris that referenced this pull request Aug 10, 2023
apache#22115)

Optimization "select count(*) from table" stmtement , push down "count" type to BE.
support file type : parquet ,orc in hive .

1. 4kfiles , 60kwline num
    before:  1 min 37.70 sec
    after:   50.18 sec

2. 50files , 60kwline num
    before: 1.12 sec
    after: 0.82 sec
xiaokang pushed a commit that referenced this pull request Aug 11, 2023
#22115)

Optimization "select count(*) from table" stmtement , push down "count" type to BE.
support file type : parquet ,orc in hive .

1. 4kfiles , 60kwline num
    before:  1 min 37.70 sec
    after:   50.18 sec

2. 50files , 60kwline num
    before: 1.12 sec
    after: 0.82 sec
morningman pushed a commit to morningman/doris that referenced this pull request Aug 16, 2023
apache#22115)

Optimization "select count(*) from table" stmtement , push down "count" type to BE.
support file type : parquet ,orc in hive .

1. 4kfiles , 60kwline num
    before:  1 min 37.70 sec
    after:   50.18 sec

2. 50files , 60kwline num
    before: 1.12 sec
    after: 0.82 sec
morningman pushed a commit that referenced this pull request Oct 11, 2023
… with only one column. (#25222)

after pr #22115 .

Fixed the bug that when selecting count(*) from table, if the table has only one column, the aggregate count is not pushed down.
xiaokang pushed a commit that referenced this pull request Oct 11, 2023
… with only one column. (#25222)

after pr #22115 .

Fixed the bug that when selecting count(*) from table, if the table has only one column, the aggregate count is not pushed down.
dutyu pushed a commit to dutyu/doris that referenced this pull request Oct 28, 2023
… with only one column. (apache#25222)

after pr apache#22115 .

Fixed the bug that when selecting count(*) from table, if the table has only one column, the aggregate count is not pushed down.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by one committer. dev/2.0.1-merged merge_conflict reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants