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

Avoid RowConverter for multi column grouping #12269

Draft
wants to merge 27 commits into
base: main
Choose a base branch
from

Conversation

jayzhan211
Copy link
Contributor

@jayzhan211 jayzhan211 commented Aug 31, 2024

Which issue does this PR close?

Closes #.

Rationale for this change

To avoid Row converter in multi group by clause, we add equality check for group values Array.

We can see a improvement on group by query (much more for string types). The downside is that this is type-specific design unlike Rows that covers all the types

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

Benchmark

Query after 37 is removed since DateTime is not supported

┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Query        ┃       main ┃  row-group ┃        Change ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ QQuery 0     │     0.40ms │     0.48ms │  1.19x slower │
│ QQuery 1     │    43.92ms │    46.27ms │  1.05x slower │
│ QQuery 2     │    76.59ms │    76.90ms │     no change │
│ QQuery 3     │    63.93ms │    67.31ms │  1.05x slower │
│ QQuery 4     │   447.49ms │   426.92ms │     no change │
│ QQuery 5     │   704.75ms │   680.61ms │     no change │
│ QQuery 6     │    36.18ms │    35.58ms │     no change │
│ QQuery 7     │    37.50ms │    36.56ms │     no change │
│ QQuery 8     │   687.91ms │   599.47ms │ +1.15x faster │
│ QQuery 9     │   654.23ms │   615.37ms │ +1.06x faster │
│ QQuery 10    │   204.86ms │   175.98ms │ +1.16x faster │
│ QQuery 11    │   237.91ms │   195.13ms │ +1.22x faster │
│ QQuery 12    │   758.26ms │   695.74ms │ +1.09x faster │
│ QQuery 13    │  1011.35ms │   885.85ms │ +1.14x faster │
│ QQuery 14    │   980.44ms │   883.32ms │ +1.11x faster │
│ QQuery 15    │   544.60ms │   468.27ms │ +1.16x faster │
│ QQuery 16    │  1751.52ms │  1318.86ms │ +1.33x faster │
│ QQuery 17    │  1530.76ms │  1311.78ms │ +1.17x faster │
│ QQuery 18    │  3702.09ms │  4322.81ms │  1.17x slower │
│ QQuery 19    │    53.09ms │    52.30ms │     no change │
│ QQuery 20    │  1535.97ms │  1475.38ms │     no change │
│ QQuery 21    │  1830.57ms │  1747.03ms │     no change │
│ QQuery 22    │  4105.92ms │  3851.14ms │ +1.07x faster │
│ QQuery 23    │  8317.37ms │  8089.16ms │     no change │
│ QQuery 24    │   498.14ms │   479.31ms │     no change │
│ QQuery 25    │   506.65ms │   491.19ms │     no change │
│ QQuery 26    │   571.42ms │   544.09ms │     no change │
│ QQuery 27    │  1323.25ms │  1325.59ms │     no change │
│ QQuery 28    │ 10284.17ms │ 10243.26ms │     no change │
│ QQuery 29    │   404.45ms │   441.24ms │  1.09x slower │
│ QQuery 30    │   837.55ms │   847.60ms │     no change │
│ QQuery 31    │   829.55ms │   779.72ms │ +1.06x faster │
│ QQuery 32    │  4698.41ms │  3555.64ms │ +1.32x faster │
│ QQuery 33    │  4180.51ms │  4229.86ms │     no change │
│ QQuery 34    │  4055.17ms │  3981.71ms │     no change │
│ QQuery 35    │  1015.82ms │  1195.95ms │  1.18x slower │
│ QQuery 36    │   143.36ms │   154.85ms │  1.08x slower │
│ QQuery 37    │    99.73ms │   105.03ms │  1.05x slower │
└──────────────┴────────────┴────────────┴───────────────┘

@github-actions github-actions bot added physical-expr Physical Expressions sqllogictest SQL Logic Tests (.slt) labels Aug 31, 2024
@jayzhan211
Copy link
Contributor Author

jayzhan211 commented Sep 2, 2024

@alamb The approach in this PR is to replace RowConverter and check the equality of the group by values by accessing the certain row and iterate all the group by expressions. The downside is that we need to have type-specific implementation but we could see it outperform Rows by eliminating the cost of Rows append and push. Also, this doesn't make sense to upstream to Arrow for me, it is group by specific implementation, so we need to maintain this in Datafusion. Would like an early feedback on this approach!

I'm thinking of support only primitive, string, datetime those non-nested type. For other less common nested types maybe we just fallback to Rows.

}

impl<T: ArrowPrimitiveType> ArrayEq for PrimitiveGroupValueBuilder<T> {
fn equal_to(&self, lhs_row: usize, array: &ArrayRef, rhs_row: usize) -> bool {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

equal_to and append_val are two core functions.

equal_to is to compare the incoming row with the row in group value builder
append_val is to add row into group value builder

@alamb
Copy link
Contributor

alamb commented Sep 2, 2024

Thanks @jayzhan211 -- I will try and review this over the next day or two

(I am catching up from being out last week and I am not back full time until this Thursday)

}

for (i, group_val) in group_values_v2.iter().enumerate() {
if !compare_equal(group_val.as_ref(), *group_idx, &cols[i], row) {
Copy link
Contributor

Choose a reason for hiding this comment

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

As this is called in a loop, this can be optimized/specialized for certain cases like: do the arrays have any nulls or not.

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 don't get it how could I further optimize the loop based on nulls 🤔

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 the idea would be change compare_equal to take advantage of cases when, for example, it was known the values couldn't be null (so checking Option isn't needed)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, indeed 👍

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

TLDR is I think this is a really neat idea @jayzhan211 -- in essence it seems to me this PR basically changes from Row comparison to Column by column comparison.

The theory with using RowCoverter at first I believe is that:

  1. It handled all possible types and combinations
  2. The theory was that time spent creating the Row would be paid back by faster comparisons by avoiding dynamic dispatch.

Your benchmark numbers seem to show different results 👌

I thought about how the performance could be so good and I suppose it does make sense because for most aggregate queries, many of the rows will go into an existing group -- so the cost of copying the input, just to find it isn't needed is outweighted

Also, this doesn't make sense to upstream to Arrow for me, it is group by specific implementation, so we need to maintain this in Datafusion. Would like an early feedback on this approach!

I looked at this and I think we could potentially reuse a lot of what is upstream in arrow-rs 's builders. I left comments

I am running the clickbench benchmarks to see if I can confirm the results. If so, I suggest we try and reuse the builders from arrow-rs as much as possible and see how elegant we can make this PR.

But all in all, really nicely done 👏

Comment on lines 305 to 259
let mut group_values_v2 = self
.group_values_v2
.take()
.expect("Can not emit from empty rows");
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a neat optimization as well -- as it saves a copy of the intermediate group values 👍

// }
// }

pub struct ByteGroupValueBuilderNaive<O>
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to my comment above, this looks very similar to the GenericBinaryBuilder in arrow -- it would be great if we could simply reuse that instead of a significant amount of copying 🤔

fn build(self: Box<Self>) -> ArrayRef;
}

pub struct PrimitiveGroupValueBuilder<T: ArrowPrimitiveType>(Vec<Option<T::Native>>);
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks very similar to PrimitiveBuilder in arrow-rs to me https://docs.rs/arrow/latest/arrow/array/struct.PrimitiveBuilder.html (though I think PrimitiveBuilder is likely faster / handles nulls better)

I wonder if you could implement ArrayEq for PrimitiveBuilder using the methods like https://docs.rs/arrow/latest/arrow/array/struct.PrimitiveBuilder.html#method.values_slice

If so I think you would have a very compelling PR here

}

for (i, group_val) in group_values_v2.iter().enumerate() {
if !compare_equal(group_val.as_ref(), *group_idx, &cols[i], row) {
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 the idea would be change compare_equal to take advantage of cases when, for example, it was known the values couldn't be null (so checking Option isn't needed)

@@ -35,9 +35,4 @@ SELECT "URL", COUNT(*) AS c FROM hits GROUP BY "URL" ORDER BY c DESC LIMIT 10;
SELECT 1, "URL", COUNT(*) AS c FROM hits GROUP BY 1, "URL" ORDER BY c DESC LIMIT 10;
SELECT "ClientIP", "ClientIP" - 1, "ClientIP" - 2, "ClientIP" - 3, COUNT(*) AS c FROM hits GROUP BY "ClientIP", "ClientIP" - 1, "ClientIP" - 2, "ClientIP" - 3 ORDER BY c DESC LIMIT 10;
SELECT "URL", COUNT(*) AS PageViews FROM hits WHERE "CounterID" = 62 AND "EventDate"::INT::DATE >= '2013-07-01' AND "EventDate"::INT::DATE <= '2013-07-31' AND "DontCountHits" = 0 AND "IsRefresh" = 0 AND "URL" <> '' GROUP BY "URL" ORDER BY PageViews DESC LIMIT 10;
SELECT "Title", COUNT(*) AS PageViews FROM hits WHERE "CounterID" = 62 AND "EventDate"::INT::DATE >= '2013-07-01' AND "EventDate"::INT::DATE <= '2013-07-31' AND "DontCountHits" = 0 AND "IsRefresh" = 0 AND "Title" <> '' GROUP BY "Title" ORDER BY PageViews DESC LIMIT 10;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are these queries removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because I haven't implement DateTime builder, so couldn't pass the test

@alamb
Copy link
Contributor

alamb commented Sep 9, 2024

TLDR is I ran the benchmarks and it does appear to make a measurable performance improvement on several queries 👍

++ BENCH_BRANCH_NAME=row-group
++ ./bench.sh compare main_base row-group
Comparing main_base and row-group
--------------------
Benchmark clickbench_1.json
--------------------
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Query        ┃  main_base ┃  row-group ┃        Change ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ QQuery 0     │     0.69ms │     0.70ms │     no change │
│ QQuery 1     │    68.87ms │    69.04ms │     no change │
│ QQuery 2     │   122.40ms │   122.39ms │     no change │
│ QQuery 3     │   129.14ms │   129.84ms │     no change │
│ QQuery 4     │   958.71ms │   950.60ms │     no change │
│ QQuery 5     │  1072.42ms │  1065.00ms │     no change │
│ QQuery 6     │    64.15ms │    65.46ms │     no change │
│ QQuery 7     │    72.57ms │    72.23ms │     no change │
│ QQuery 8     │  1427.25ms │  1352.90ms │ +1.05x faster │
│ QQuery 9     │  1328.70ms │  1333.45ms │     no change │
│ QQuery 10    │   444.86ms │   435.72ms │     no change │
│ QQuery 11    │   493.91ms │   475.07ms │     no change │
│ QQuery 12    │  1158.46ms │  1154.09ms │     no change │
│ QQuery 13    │  2124.34ms │  1776.44ms │ +1.20x faster │
│ QQuery 14    │  1607.17ms │  1306.73ms │ +1.23x faster │
│ QQuery 15    │  1078.30ms │  1062.72ms │     no change │
│ QQuery 16    │  2885.78ms │  2525.19ms │ +1.14x faster │
│ QQuery 17    │  2799.52ms │  2470.93ms │ +1.13x faster │
│ QQuery 18    │  5575.63ms │  5524.24ms │     no change │
│ QQuery 19    │   119.57ms │   118.24ms │     no change │
│ QQuery 20    │  1656.36ms │  1675.11ms │     no change │
│ QQuery 21    │  2014.67ms │  2028.74ms │     no change │
│ QQuery 22    │  4849.99ms │  4824.94ms │     no change │
│ QQuery 23    │ 11274.06ms │ 11309.82ms │     no change │
│ QQuery 24    │   761.95ms │   754.26ms │     no change │
│ QQuery 25    │   667.54ms │   668.69ms │     no change │
│ QQuery 26    │   821.70ms │   839.38ms │     no change │
│ QQuery 27    │  2467.71ms │  2493.84ms │     no change │
│ QQuery 28    │ 15737.24ms │ 15634.42ms │     no change │
│ QQuery 29    │   560.78ms │   551.43ms │     no change │
│ QQuery 30    │  1296.29ms │  1242.39ms │     no change │
│ QQuery 31    │  1318.14ms │  1291.30ms │     no change │
│ QQuery 32    │  4569.20ms │  4241.25ms │ +1.08x faster │
│ QQuery 33    │  5020.91ms │  5031.03ms │     no change │
│ QQuery 34    │  5014.64ms │  4965.98ms │     no change │
│ QQuery 35    │  1818.84ms │  1850.31ms │     no change │
│ QQuery 36    │   316.76ms │   302.74ms │     no change │
│ QQuery 37    │   217.15ms │   219.32ms │     no change │
│ QQuery 38    │   188.03ms │   191.14ms │     no change │
│ QQuery 39    │  1039.10ms │   788.09ms │ +1.32x faster │
│ QQuery 40    │    86.06ms │    83.63ms │     no change │
│ QQuery 41    │    77.68ms │    79.76ms │     no change │
│ QQuery 42    │    97.39ms │    91.99ms │ +1.06x faster │
└──────────────┴────────────┴────────────┴───────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ Benchmark Summary        ┃            ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ Total Time (main_base)   │ 85404.65ms │
│ Total Time (row-group)   │ 83170.54ms │
│ Average Time (main_base) │  1986.15ms │
│ Average Time (row-group) │  1934.20ms │
│ Queries Faster           │          8 │
│ Queries Slower           │          0 │
│ Queries with No Change   │         35 │
└──────────────────────────┴────────────┘
--------------------
Benchmark clickbench_extended.json
--------------------
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━┓
┃ Query        ┃ main_base ┃ row-group ┃    Change ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━┩
│ QQuery 0     │ 2652.87ms │ 2682.38ms │ no change │
│ QQuery 1     │  793.53ms │  794.12ms │ no change │
│ QQuery 2     │ 1576.90ms │ 1609.73ms │ no change │
│ QQuery 3     │  705.29ms │  718.99ms │ no change │
└──────────────┴───────────┴───────────┴───────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┓
┃ Benchmark Summary        ┃           ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━┩
│ Total Time (main_base)   │ 5728.58ms │
│ Total Time (row-group)   │ 5805.22ms │
│ Average Time (main_base) │ 1432.15ms │
│ Average Time (row-group) │ 1451.31ms │
│ Queries Faster           │         0 │
│ Queries Slower           │         0 │
│ Queries with No Change   │         4 │
└──────────────────────────┴───────────┘
--------------------
Benchmark clickbench_partitioned.json
--------------------
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Query        ┃  main_base ┃  row-group ┃        Change ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ QQuery 0     │     2.29ms │     2.27ms │     no change │
│ QQuery 1     │    38.05ms │    37.76ms │     no change │
│ QQuery 2     │    93.47ms │    93.56ms │     no change │
│ QQuery 3     │    98.55ms │    96.67ms │     no change │
│ QQuery 4     │   902.00ms │   910.55ms │     no change │
│ QQuery 5     │   937.33ms │   936.86ms │     no change │
│ QQuery 6     │    34.33ms │    33.78ms │     no change │
│ QQuery 7     │    40.59ms │    39.35ms │     no change │
│ QQuery 8     │  1368.30ms │  1296.26ms │ +1.06x faster │
│ QQuery 9     │  1293.07ms │  1273.53ms │     no change │
│ QQuery 10    │   339.78ms │   331.25ms │     no change │
│ QQuery 11    │   375.98ms │   381.26ms │     no change │
│ QQuery 12    │  1025.16ms │  1034.74ms │     no change │
│ QQuery 13    │  1811.09ms │  1792.68ms │     no change │
│ QQuery 14    │  1453.37ms │  1448.76ms │     no change │
│ QQuery 15    │  1012.38ms │  1012.83ms │     no change │
│ QQuery 16    │  2746.71ms │  2728.55ms │     no change │
│ QQuery 17    │  2719.38ms │  2632.64ms │     no change │
│ QQuery 18    │  5524.24ms │  5525.66ms │     no change │
│ QQuery 19    │    92.83ms │    90.08ms │     no change │
│ QQuery 20    │  1752.39ms │  1751.25ms │     no change │
│ QQuery 21    │  1946.27ms │  1981.08ms │     no change │
│ QQuery 22    │  4974.66ms │  5049.46ms │     no change │
│ QQuery 23    │  9841.76ms │  9781.88ms │     no change │
│ QQuery 24    │   549.84ms │   559.25ms │     no change │
│ QQuery 25    │   467.91ms │   475.16ms │     no change │
│ QQuery 26    │   631.52ms │   617.63ms │     no change │
│ QQuery 27    │  2445.52ms │  2463.11ms │     no change │
│ QQuery 28    │ 14923.62ms │ 15024.79ms │     no change │
│ QQuery 29    │   530.70ms │   523.81ms │     no change │
│ QQuery 30    │  1106.49ms │  1060.93ms │     no change │
│ QQuery 31    │  1140.91ms │  1090.09ms │     no change │
│ QQuery 32    │  4550.65ms │  4133.54ms │ +1.10x faster │
│ QQuery 33    │  4929.55ms │  4922.02ms │     no change │
│ QQuery 34    │  4789.55ms │  4834.44ms │     no change │
│ QQuery 35    │  1753.55ms │  1829.42ms │     no change │
│ QQuery 36    │   283.39ms │   267.52ms │ +1.06x faster │
│ QQuery 37    │   120.66ms │   122.89ms │     no change │
│ QQuery 38    │   141.70ms │   136.39ms │     no change │
│ QQuery 39    │   897.86ms │   918.07ms │     no change │
│ QQuery 40    │    58.14ms │    61.45ms │  1.06x slower │
│ QQuery 41    │    48.73ms │    48.17ms │     no change │
│ QQuery 42    │    66.33ms │    63.97ms │     no change │
└──────────────┴────────────┴────────────┴───────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ Benchmark Summary        ┃            ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ Total Time (main_base)   │ 79860.62ms │
│ Total Time (row-group)   │ 79415.32ms │
│ Average Time (main_base) │  1857.22ms │
│ Average Time (row-group) │  1846.87ms │
│ Queries Faster           │          3 │
│ Queries Slower           │          1 │
│ Queries with No Change   │         39 │

@jayzhan211
Copy link
Contributor Author

┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Query        ┃       main ┃  row-group ┃        Change ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ QQuery 0     │     0.53ms │     0.41ms │ +1.31x faster │
│ QQuery 1     │    49.01ms │    41.52ms │ +1.18x faster │
│ QQuery 2     │    88.41ms │    79.98ms │ +1.11x faster │
│ QQuery 3     │    71.89ms │    73.76ms │     no change │
│ QQuery 4     │   475.98ms │   435.24ms │ +1.09x faster │
│ QQuery 5     │   715.67ms │   689.91ms │     no change │
│ QQuery 6     │    36.87ms │    38.72ms │  1.05x slower │
│ QQuery 7     │    42.85ms │    44.72ms │     no change │
│ QQuery 8     │   767.47ms │   682.42ms │ +1.12x faster │
│ QQuery 9     │   698.12ms │   687.16ms │     no change │
│ QQuery 10    │   214.09ms │   202.99ms │ +1.05x faster │
│ QQuery 11    │   233.88ms │   227.44ms │     no change │
│ QQuery 12    │   765.70ms │   763.87ms │     no change │
│ QQuery 13    │  1105.55ms │   967.40ms │ +1.14x faster │
│ QQuery 14    │  1087.28ms │   904.65ms │ +1.20x faster │
│ QQuery 15    │   538.36ms │   528.94ms │     no change │
│ QQuery 16    │  1707.60ms │  1418.83ms │ +1.20x faster │
│ QQuery 17    │  1580.22ms │  1281.82ms │ +1.23x faster │
│ QQuery 18    │  4503.70ms │  4718.10ms │     no change │
│ QQuery 19    │    58.30ms │    68.69ms │  1.18x slower │
│ QQuery 20    │  1015.23ms │  1086.18ms │  1.07x slower │
│ QQuery 21    │  1306.73ms │  1345.37ms │     no change │
│ QQuery 22    │  3515.27ms │  3727.30ms │  1.06x slower │
│ QQuery 23    │  8564.19ms │  8835.99ms │     no change │
│ QQuery 24    │   509.14ms │   524.45ms │     no change │
│ QQuery 25    │   506.78ms │   517.49ms │     no change │
│ QQuery 26    │   586.24ms │   566.43ms │     no change │
│ QQuery 27    │  1418.28ms │  1498.42ms │  1.06x slower │
│ QQuery 28    │ 10867.59ms │ 11017.18ms │     no change │
│ QQuery 29    │   410.02ms │   419.97ms │     no change │
│ QQuery 30    │   865.76ms │   820.34ms │ +1.06x faster │
│ QQuery 31    │   779.85ms │   776.05ms │     no change │
│ QQuery 32    │  4989.34ms │  3710.45ms │ +1.34x faster │
│ QQuery 33    │  5195.54ms │  5364.02ms │     no change │
│ QQuery 34    │  4955.46ms │  5048.30ms │     no change │
│ QQuery 35    │  1082.95ms │  1171.24ms │  1.08x slower │
│ QQuery 36    │   143.30ms │   144.68ms │     no change │
│ QQuery 37    │    99.65ms │   108.31ms │  1.09x slower │
│ QQuery 38    │   104.12ms │   108.27ms │     no change │
│ QQuery 39    │   383.56ms │   321.16ms │ +1.19x faster │
│ QQuery 40    │    37.12ms │    36.89ms │     no change │
│ QQuery 41    │    34.16ms │    33.11ms │     no change │
│ QQuery 42    │    42.21ms │    41.49ms │     no change │
└──────────────┴────────────┴────────────┴───────────────┘

@jayzhan211
Copy link
Contributor Author

jayzhan211 commented Sep 14, 2024

@alamb I found FirstN mode is non-trivial If I switch to Arrow's Builder instead of Vec what I had done before. Is it reasonable to implement takeN logic in Arrow's Builder upstream?

Or maybe we should revert to the previous vector implementation since the performance doesn't differ a lot and it is easier for FirstN mode to implement. And, there are a few PRs showing that Vec outperform Builder mode.

#12460
#12121

@alamb
Copy link
Contributor

alamb commented Sep 15, 2024

@alamb I found FirstN mode is non-trivial If I switch to Arrow's Builder instead of Vec what I had done before. Is it reasonable to implement takeN logic in Arrow's Builder upstream?

I think using Vec, if possible, is likely to be the best idea as Vec is well understood and highly optimized in Rust (and also has a fast conversion to Arrow arrays)

@alamb
Copy link
Contributor

alamb commented Sep 15, 2024

@jayzhan211 BTW the results in #12269 (comment) are quite impressive

This is a great example of using data driven decisions to come to a better internal architecture / approach (e.g showing with data that using single row comparisons is actually better than using RowCoverter). Very nice 👌

@jayzhan211
Copy link
Contributor Author

Query that compute with Datetime are slower 🤔

@github-actions github-actions bot removed the sqllogictest SQL Logic Tests (.slt) label Sep 16, 2024
array: &ArrayRef,
rhs_row: usize,
) -> bool {
array_row.equal_to(lhs_row, array, rhs_row)
Copy link
Contributor Author

@jayzhan211 jayzhan211 Sep 16, 2024

Choose a reason for hiding this comment

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

Nulls are handled in the equal_to, is there any other place we could further optimize?

Copy link
Contributor

Choose a reason for hiding this comment

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

One idea I had is that you could defer actually copying the new rows into group_values so rather than calling the function once for each new group, you could call it once per batch, and it could insert all the new values in one function call

That would save some function call overhead as well as the downcasting of arrays and maybe would vectorize better

@github-actions github-actions bot added the sqllogictest SQL Logic Tests (.slt) label Sep 16, 2024
Signed-off-by: jayzhan211 <jayzhan211@gmail.com>
Signed-off-by: jayzhan211 <jayzhan211@gmail.com>
Signed-off-by: jayzhan211 <jayzhan211@gmail.com>
Signed-off-by: jayzhan211 <jayzhan211@gmail.com>
Signed-off-by: jayzhan211 <jayzhan211@gmail.com>
Signed-off-by: jayzhan211 <jayzhan211@gmail.com>
Signed-off-by: jayzhan211 <jayzhan211@gmail.com>
Signed-off-by: jayzhan211 <jayzhan211@gmail.com>
Signed-off-by: jayzhan211 <jayzhan211@gmail.com>
Signed-off-by: jayzhan211 <jayzhan211@gmail.com>
Signed-off-by: jayzhan211 <jayzhan211@gmail.com>
Signed-off-by: jayzhan211 <jayzhan211@gmail.com>
@@ -1380,24 +1380,16 @@ mod tests {
"+---+-----+-----------------+",
"| a | b | COUNT(1)[count] |",
"+---+-----+-----------------+",
"| | 1.0 | 1 |",
Copy link
Contributor Author

@jayzhan211 jayzhan211 Sep 17, 2024

Choose a reason for hiding this comment

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

The change is consistent with the one that run in slt in main.
Not sure which one is the expected behaviour 🤔

The only difference is that we use GroupValuesRowLike instead GroupValuesRows for Float

Copy link
Contributor

Choose a reason for hiding this comment

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

When in doubt, I always run in postgres to see what it says

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 have checked both postgres and duckdb, the spill one is the expected result. But why the non-spill version has the different result

Signed-off-by: jayzhan211 <jayzhan211@gmail.com>
@alamb
Copy link
Contributor

alamb commented Sep 17, 2024

@jayzhan211 what is the status of this PR? Is it ready for another look? Do you need some help?

@jayzhan211
Copy link
Contributor Author

jayzhan211 commented Sep 17, 2024

@jayzhan211 what is the status of this PR? Is it ready for another look? Do you need some help?

The biggest challenge now is that the grouping sets result changed after I add the Float type support, and it seems that the result is not consistent with postgres. It is also not consistent for slt test on main branch. (the result in slt and rust test seems different on main branch and both postgres and duckdb has the result that is different than my current result)

Specifically, for query

postgres=# select a, b, count(*) from t group by grouping sets ((a, b), (a), (b));
 a |  b  | count 
---+-----+-------
   | 1.2 |     2
 1 |     |     1
 1 | 1.1 |     1
   | 1.1 |     1
 2 | 1.1 |     1
   |     |     3
 2 |     |     1
 1 |     |     2
   |     |     1
   | 1.2 |     2
   | 1.1 |     3

My current branch will group the values that are the same together without considering grouping sets.
Like (null, 1.2), and (null, 1.1) they have two row in postgres, but I will only have a single row.

@jayzhan211
Copy link
Contributor Author

jayzhan211 commented Sep 18, 2024

Given the comment here #7400 (comment)

  1. I think we have different final result of grouping sets from postgres and duckdb, this PR doesn't change the behaviour
  2. The result change in check_grouping_sets is the partial aggregate state so it might be expected, but need to check. The reason why the partial aggregate result changed might be the less mem usage of this PR, so I adjust the mem limit and have the same result as previous, this indicates this PR not only has improve performance but also has less mem usage.

@github-actions github-actions bot added the core Core DataFusion crate label Sep 18, 2024
…lues

Signed-off-by: jayzhan211 <jayzhan211@gmail.com>
@github-actions github-actions bot removed the core Core DataFusion crate label Sep 18, 2024
Signed-off-by: jayzhan211 <jayzhan211@gmail.com>
Signed-off-by: jayzhan211 <jayzhan211@gmail.com>
@jayzhan211 jayzhan211 marked this pull request as ready for review September 18, 2024 08:59
@alamb
Copy link
Contributor

alamb commented Sep 18, 2024

Thanks @jayzhan211 -- I am running the benchmarks on this PR and plan to review it carefully either later today or tomorrow

🚀

@alamb alamb changed the title Avoid RowConverter for multi group by Avoid RowConverter for multi column grouping Sep 18, 2024
@alamb
Copy link
Contributor

alamb commented Sep 18, 2024

I tried to run the clickbench benchmarks and they failed like this:

ote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'tokio-runtime-worker' panicked at datafusion/physical-plan/src/aggregates/group_values/row_like.rs:161:31:
not yet implemented: Binary not impl
thread 'tokio-runtime-worker' panicked at datafusion/physical-plan/src/aggregates/group_values/row_like.rs:161:31:
not yet implemented: Binary not impl
thread 'tokio-runtime-worker' panicked at datafusion/physical-plan/src/aggregates/group_values/row_like.rs:161:31:
not yet implemented: Binary not impl
thread 'tokio-runtime-worker' panicked at datafusion/physical-plan/src/aggregates/group_values/row_like.rs:161:31:
not yet implemented: Binary not impl
thread 'tokio-runtime-worker' panicked at datafusion/physical-plan/src/aggregates/group_values/row_like.rs:161:31:
not yet implemented: Binary not impl
thread 'tokio-runtime-worker' panicked at datafusion/physical-plan/src/aggregates/group_values/row_like.rs:161:31:
not yet implemented: Binary not impl
thread 'tokio-runtime-worker' panicked at datafusion/physical-plan/src/aggregates/group_values/row_like.rs:161:31:
not yet implemented: Binary not impl
thread 'tokio-runtime-worker' panicked at datafusion/physical-plan/src/aggregates/group_values/row_like.rs:161:31:
not yet implemented: Binary not impl
thread 'tokio-runtime-worker' panicked at datafusion/physical-plan/src/aggregates/group_values/row_like.rs:161:31:
not yet implemented: Binary not impl
thread 'tokio-runtime-worker' panicked at datafusion/physical-plan/src/aggregates/group_values/row_like.rs:161:31:
not yet implemented: Binary not impl
thread 'tokio-runtime-worker' panicked at datafusion/physical-plan/src/aggregates/group_values/row_like.rs:161:31:
not yet implemented: Binary not impl
Error: External(Context("Join Error", External(JoinError::Panic(Id(26806), "not yet implemented: Binary not impl", ...))))

Signed-off-by: jayzhan211 <jayzhan211@gmail.com>
Signed-off-by: jayzhan211 <jayzhan211@gmail.com>
@alamb
Copy link
Contributor

alamb commented Sep 20, 2024

this is next on my list


pub struct PrimitiveGroupValueBuilder<T: ArrowPrimitiveType> {
group_values: Vec<T::Native>,
nulls: Vec<bool>,
Copy link
Contributor

Choose a reason for hiding this comment

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

We can probably make this faster using a BooleanBufferBuilder or something similar

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

TLDR in my opinion this PR is amazing @jayzhan211 -- I found it a pleasure to read and I think the engineering displayed getting here is 🦾 very impressive

so-beautiful
(I seem to be using this a lot recently 😁 )

I think this shows that storing multi-column group values also in columns is significantly faster than converting to row. Very very cool. I also think there are several other potential improvements here for improving performance, but all the better if this works well as is

I am rerunning benchmarks and will post the results here but assuming they still show an improvement I think this PR could be merged it as is (I have a few suggestions) but I think it is ready

Some nice to haves / follow ons would be:

  1. Improve documentation (I have some ideas, but this PR is already very well commented)

  2. Add some additional testing / fuzz testing (especially for nulls/ non null values) for cases (int a, string b) and (string a, int b)

  3. Implement a ByteGroupValueBuilder for StringView and the other primitive based types (e.g. DecimalArray, the date/time stuff, etc)


fn append_val(&mut self, array: &ArrayRef, row: usize) {
// non-null fast path
if !self.nullable || !array.is_null(row) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be

Suggested change
if !self.nullable || !array.is_null(row) {
if !self.nullable && !array.is_null(row) {

To catch the first row that is nullable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should or them
nullable is whether the column is nullable or not, so we don't need to check array.is_null(row) if the column is declared non-null, just assume every thing is non-null

// Sanity array type
match self.output_type {
OutputType::Binary => {
assert!(matches!(
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can make this go even faster with debug_assert or something.

// SAFETY:
// 1. the offsets were constructed safely
//
// 2. we asserted the input arrays were all the correct type and
Copy link
Contributor

Choose a reason for hiding this comment

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

💯

/// The actual group by values, stored column-wise. Compare from
/// the left to right, each column is stored as `ArrayRowEq`.
/// This is shown faster than the row format
group_values: Option<Vec<Box<dyn ArrayRowEq>>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you explain the difference between what None and Some(vec![]) is?

I wonder if you can make this simpler by just using a Vec and checking for empty vec?

Suggested change
group_values: Option<Vec<Box<dyn ArrayRowEq>>>,
group_values: Vec<Box<dyn ArrayRowEq>>,

fn take_n(&mut self, n: usize) -> ArrayRef {
assert!(self.len() >= n);

let mut nulls_count = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

The null / shifting logic here feels like it should be unit tested to me (maybe fuzz testing would be enough)

Also, I am reminded of @kazuyukitanimura 's PR in arrow to improve set_bits apache/arrow-rs#6288 which I think could be used here as well and now even more optimized

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 found my take_n for string is completely wrong 😅

fn take_n(&mut self, n: usize) -> ArrayRef;
}

pub struct PrimitiveGroupValueBuilder<T: ArrowPrimitiveType> {
Copy link
Contributor

Choose a reason for hiding this comment

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

At a high level, I feel like this builder and the ByteGroupValueBuilder feel like they are very similar to builders in arrow-rs. I don't know if we could actually upstream any of this / use the upstream builders, but if we could we could probably save some significant time

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, when @wiedld and I were discussing this PR, we realized this is quite similar to

I wonder if we could potentially use that (i.e. impl ArrayRowEq for GroupValuesPrimitive) 🤔 -- that code is already pretty well tested and optimized 🤔

Though maybe null handling has to be different

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is another difference. GroupValuesRowLike can handle mixed type like i32 + utf8. GroupValuesPrimitive could only be extended to multiple primitive types but not mixed with utf8. Otherwise, it will be the same as GroupValuesRowLike

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess I was imagining that GroupValuesRowLike would continue to have a Vec<Box<dyn ArrayRowEq>> but we could implement ArrayRowEq for GroupValuesPrimtive and GroupValuesBinary, etc

@@ -0,0 +1,393 @@
// Licensed to the Apache Software Foundation (ASF) under one
Copy link
Contributor

Choose a reason for hiding this comment

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

This module feels like it is an implementation detail of datafusion/physical-plan/src/aggregates/group_values/row_like.rs, so I suggest putting it in that module (physical-plan rather than physical-expr-common)

array: &ArrayRef,
rhs_row: usize,
) -> bool {
array_row.equal_to(lhs_row, array, rhs_row)
Copy link
Contributor

Choose a reason for hiding this comment

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

One idea I had is that you could defer actually copying the new rows into group_values so rather than calling the function once for each new group, you could call it once per batch, and it could insert all the new values in one function call

That would save some function call overhead as well as the downcasting of arrays and maybe would vectorize better

.map(|f| f.data_type())
.all(has_row_like_feature)
{
Ok(Box::new(GroupValuesRowLike::try_new(schema)?))
Copy link
Contributor

Choose a reason for hiding this comment

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

Reading this from afar, I would say the name GroupValuesRowLike is confusing to me as it seems the key is that the group values are stored in columns rather than rows 🤔

Perhaps renaming GroupValuesRowLike to GroupValuesColumn would make this clearer

Comment on lines 40 to 48
/// Trait for group values column-wise row comparison
pub trait ArrayRowEq: Send + Sync {
fn equal_to(&self, lhs_row: usize, array: &ArrayRef, rhs_row: usize) -> bool;
fn append_val(&mut self, array: &ArrayRef, row: usize);
fn len(&self) -> usize;
fn is_empty(&self) -> bool;
fn build(self: Box<Self>) -> ArrayRef;
fn take_n(&mut self, n: usize) -> ArrayRef;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Here are some doc suggestions:

Suggested change
/// Trait for group values column-wise row comparison
pub trait ArrayRowEq: Send + Sync {
fn equal_to(&self, lhs_row: usize, array: &ArrayRef, rhs_row: usize) -> bool;
fn append_val(&mut self, array: &ArrayRef, row: usize);
fn len(&self) -> usize;
fn is_empty(&self) -> bool;
fn build(self: Box<Self>) -> ArrayRef;
fn take_n(&mut self, n: usize) -> ArrayRef;
}
/// Trait for group values column-wise row comparison
///
/// Implementations of this trait store a in-progress collection of group values
/// (similar to various builders in Arrow-rs) that allow for quick comparison to
/// incoming rows.
///
pub trait ArrayRowEq: Send + Sync {
/// Returns equal if the row stored in this builder at `lhs_row` is equal to
/// the row in `array` at `rhs_row`
fn equal_to(&self, lhs_row: usize, array: &ArrayRef, rhs_row: usize) -> bool;
/// Appends the row at `row` in `array` to this builder
fn append_val(&mut self, array: &ArrayRef, row: usize);
/// Returns the number of rows stored in this builder
fn len(&self) -> usize;
/// Returns true if this builder is empty
fn is_empty(&self) -> bool;
/// Builds a new array from all of the stored rows
fn build(self: Box<Self>) -> ArrayRef;
/// Builds a new array from the first `n` stored rows, shifting the
/// remaining rows to the start of the builder
fn take_n(&mut self, n: usize) -> ArrayRef;
}

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

🚀

Nice work @jayzhan211

I think we can continue to improve / optimize this code, but the benchmark results speak for themselves. Really nice work

--------------------
Benchmark clickbench_1.json
--------------------
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Query        ┃  main_base ┃  row-group ┃        Change ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ QQuery 0     │     0.65ms │     0.67ms │     no change │
│ QQuery 1     │    71.17ms │    71.11ms │     no change │
│ QQuery 2     │   123.47ms │   125.05ms │     no change │
│ QQuery 3     │   135.88ms │   129.59ms │     no change │
│ QQuery 4     │   977.05ms │   969.01ms │     no change │
│ QQuery 5     │  1097.08ms │  1103.84ms │     no change │
│ QQuery 6     │    64.50ms │    66.47ms │     no change │
│ QQuery 7     │    83.28ms │    81.94ms │     no change │
│ QQuery 8     │  1471.54ms │  1394.71ms │ +1.06x faster │
│ QQuery 9     │  1391.33ms │  1362.55ms │     no change │
│ QQuery 10    │   471.01ms │   455.89ms │     no change │
│ QQuery 11    │   518.11ms │   495.06ms │     no change │
│ QQuery 12    │  1226.53ms │  1228.29ms │     no change │
│ QQuery 13    │  2239.79ms │  1867.38ms │ +1.20x faster │
│ QQuery 14    │  1679.84ms │  1336.33ms │ +1.26x faster │
│ QQuery 15    │  1147.96ms │  1140.62ms │     no change │
│ QQuery 16    │  3027.32ms │  2674.68ms │ +1.13x faster │
│ QQuery 17    │  2811.21ms │  2472.53ms │ +1.14x faster │
│ QQuery 18    │  5971.43ms │  5117.77ms │ +1.17x faster │
│ QQuery 19    │   119.98ms │   119.23ms │     no change │
│ QQuery 20    │  1675.42ms │  1683.73ms │     no change │
│ QQuery 21    │  2088.10ms │  2130.67ms │     no change │
│ QQuery 22    │  5067.34ms │  5097.95ms │     no change │
│ QQuery 23    │ 12066.88ms │ 11898.76ms │     no change │
│ QQuery 24    │   798.95ms │   769.36ms │     no change │
│ QQuery 25    │   724.90ms │   689.24ms │     no change │
│ QQuery 26    │   867.08ms │   862.14ms │     no change │
│ QQuery 27    │  2609.24ms │  2600.77ms │     no change │
│ QQuery 28    │ 15367.14ms │ 16229.38ms │  1.06x slower │
│ QQuery 29    │   563.78ms │   574.95ms │     no change │
│ QQuery 30    │  1287.56ms │  1237.79ms │     no change │
│ QQuery 31    │  1364.54ms │  1282.52ms │ +1.06x faster │
│ QQuery 32    │  4735.13ms │  4309.81ms │ +1.10x faster │
│ QQuery 33    │  5307.06ms │  5354.96ms │     no change │
│ QQuery 34    │  5252.21ms │  5283.19ms │     no change │
│ QQuery 35    │  1850.47ms │  1877.84ms │     no change │
│ QQuery 36    │   317.13ms │   325.94ms │     no change │
│ QQuery 37    │   215.65ms │   223.00ms │     no change │
│ QQuery 38    │   202.05ms │   191.70ms │ +1.05x faster │
│ QQuery 39    │  1077.51ms │   847.19ms │ +1.27x faster │
│ QQuery 40    │    93.08ms │    86.30ms │ +1.08x faster │
│ QQuery 41    │    81.67ms │    77.70ms │     no change │
│ QQuery 42    │    98.51ms │    93.09ms │ +1.06x faster │
└──────────────┴────────────┴────────────┴───────────────┘


--------------------
Benchmark clickbench_partitioned.json
--------------------
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Query        ┃  main_base ┃  row-group ┃        Change ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ QQuery 0     │     2.22ms │     2.22ms │     no change │
│ QQuery 1     │    38.52ms │    38.60ms │     no change │
│ QQuery 2     │    93.93ms │    92.83ms │     no change │
│ QQuery 3     │   100.91ms │    99.54ms │     no change │
│ QQuery 4     │   935.01ms │   928.03ms │     no change │
│ QQuery 5     │   971.85ms │   977.00ms │     no change │
│ QQuery 6     │    33.86ms │    33.53ms │     no change │
│ QQuery 7     │    42.08ms │    41.74ms │     no change │
│ QQuery 8     │  1444.01ms │  1412.74ms │     no change │
│ QQuery 9     │  1319.34ms │  1355.49ms │     no change │
│ QQuery 10    │   364.25ms │   345.23ms │ +1.06x faster │
│ QQuery 11    │   397.19ms │   388.98ms │     no change │
│ QQuery 12    │  1097.11ms │  1078.08ms │     no change │
│ QQuery 13    │  1929.01ms │  1732.75ms │ +1.11x faster │
│ QQuery 14    │  1545.16ms │  1258.11ms │ +1.23x faster │
│ QQuery 15    │  1087.34ms │  1081.88ms │     no change │
│ QQuery 16    │  2953.26ms │  2597.77ms │ +1.14x faster │
│ QQuery 17    │  2741.90ms │  2378.29ms │ +1.15x faster │
│ QQuery 18    │  5821.55ms │  5101.19ms │ +1.14x faster │
│ QQuery 19    │    92.23ms │    92.97ms │     no change │
│ QQuery 20    │  1734.66ms │  1771.89ms │     no change │
│ QQuery 21    │  2058.21ms │  2044.49ms │     no change │
│ QQuery 22    │  5208.74ms │  5197.48ms │     no change │
│ QQuery 23    │ 10475.98ms │ 10422.24ms │     no change │
│ QQuery 24    │   601.41ms │   572.15ms │     no change │
│ QQuery 25    │   498.67ms │   497.77ms │     no change │
│ QQuery 26    │   660.25ms │   656.65ms │     no change │
│ QQuery 27    │  2599.62ms │  2577.07ms │     no change │
│ QQuery 28    │ 14563.07ms │ 15297.20ms │  1.05x slower │
│ QQuery 29    │   517.92ms │   524.98ms │     no change │
│ QQuery 30    │  1123.10ms │  1052.28ms │ +1.07x faster │
│ QQuery 31    │  1169.77ms │  1119.14ms │     no change │
│ QQuery 32    │  4853.42ms │  4234.03ms │ +1.15x faster │
│ QQuery 33    │  5231.77ms │  5175.85ms │     no change │
│ QQuery 34    │  5142.16ms │  5106.57ms │     no change │
│ QQuery 35    │  1818.27ms │  2074.98ms │  1.14x slower │
│ QQuery 36    │   268.04ms │   275.51ms │     no change │
│ QQuery 37    │   125.96ms │   120.91ms │     no change │
│ QQuery 38    │   140.83ms │   146.25ms │     no change │
│ QQuery 39    │   951.76ms │   749.69ms │ +1.27x faster │
│ QQuery 40    │    52.12ms │    55.88ms │  1.07x slower │
│ QQuery 41    │    47.74ms │    48.89ms │     no change │
│ QQuery 42    │    63.78ms │    61.94ms │     no change │
└──────────────┴────────────┴────────────┴───────────────┘

--------------------
Benchmark tpch_sf1.json
--------------------
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Query        ┃ main_base ┃ row-group ┃        Change ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ QQuery 1     │  252.62ms │  196.18ms │ +1.29x faster │
│ QQuery 2     │  131.31ms │  111.47ms │ +1.18x faster │
│ QQuery 3     │  138.74ms │  131.76ms │ +1.05x faster │
│ QQuery 4     │   92.29ms │   90.21ms │     no change │
│ QQuery 5     │  180.88ms │  157.42ms │ +1.15x faster │
│ QQuery 6     │   60.26ms │   53.12ms │ +1.13x faster │
│ QQuery 7     │  223.37ms │  202.25ms │ +1.10x faster │
│ QQuery 8     │  165.38ms │  169.47ms │     no change │
│ QQuery 9     │  259.49ms │  254.33ms │     no change │
│ QQuery 10    │  244.94ms │  223.46ms │ +1.10x faster │
│ QQuery 11    │  104.23ms │   93.90ms │ +1.11x faster │
│ QQuery 12    │  135.08ms │  128.36ms │     no change │
│ QQuery 13    │  304.56ms │  211.85ms │ +1.44x faster │
│ QQuery 14    │   97.08ms │   73.28ms │ +1.32x faster │
│ QQuery 15    │  128.14ms │  103.56ms │ +1.24x faster │
│ QQuery 16    │   85.69ms │   80.47ms │ +1.06x faster │
│ QQuery 17    │  246.47ms │  218.66ms │ +1.13x faster │
│ QQuery 18    │  344.79ms │  314.93ms │ +1.09x faster │
│ QQuery 19    │  162.78ms │  122.87ms │ +1.32x faster │
│ QQuery 20    │  145.63ms │  142.05ms │     no change │
│ QQuery 21    │  276.08ms │  265.45ms │     no change │
│ QQuery 22    │   65.63ms │   62.79ms │     no change │
└──────────────┴───────────┴───────────┴───────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┓
┃ Benchmark Summary        ┃           ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━┩
│ Total Time (main_base)   │ 3845.43ms │
│ Total Time (row-group)   │ 3407.84ms │
│ Average Time (main_base) │  174.79ms │
│ Average Time (row-group) │  154.90ms │
│ Queries Faster           │        15 │
│ Queries Slower           │         0 │
│ Queries with No Change   │         7 │
└──────────────────────────┴───────────┘

Signed-off-by: jayzhan211 <jayzhan211@gmail.com>
Signed-off-by: jayzhan211 <jayzhan211@gmail.com>
Signed-off-by: jayzhan211 <jayzhan211@gmail.com>
@jayzhan211 jayzhan211 marked this pull request as draft September 21, 2024 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
physical-expr Physical Expressions sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants