Skip to content
This repository was archived by the owner on Oct 10, 2025. It is now read-only.

Rel scan selection optimizations - #4558

Merged
andyfengHKU merged 3 commits into
masterfrom
rel-scan-selection-opt
Nov 24, 2024
Merged

andyfengHKU merged 3 commits into
masterfrom
rel-scan-selection-opt

Conversation

@benjaminwinger

Copy link
Copy Markdown
Contributor

The biggest optimization here is avoiding using the bitset in CSRNodeGroup::tryScanCachedTuples if it's known that all values are selected.

In some unfiltered rel table scans this improved performance of CSRNodeGroup::tryScanCachedTuples by about 4x, for a total of about a 15% on some queries I'd benchmarked which were mostly scans.

E.g. 'MATCH (v:N)-[e:E]->(v2:N) RETURN SUM(v.ID);' on the ldbc graph500-30 dataset (with 128 threads) went from ~2.65s to ~2.25s

I've also:

  • removed a couple of unnecessary std::shared_ptr copies (which are immediately destroyed).
  • Added ValueVector::forEachNonNull to consolidate some code in the aggregate functions

@ray6080 ray6080 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! @andyfengHKU can you also take a quick look into the changes regarding to null mask and aggregation functions and see if there are other places we can apply the changes in similar pattern?

Comment thread src/processor/result/result_set.cpp Outdated
~ValueVector() = default;

template<class Func>
void forEachNonNull(Func&& func) const {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can u open an issue to propagate this to unary, binary & ternary evaluator and assign the issue to @acquamarin

…if possible

bitset access is relatively slow, and may not be necessary
There are also some optimizations possible to take advantage of not having to scan the SelectionVector's buffer (though I'm not sure if we're actually taking advantage of it right now).
And I avoided the unnecessary creation/destruction of a std::shared_ptr in RelTableScanState::setNodeIDVectorToFlat by using getSelVectorUnsafe instead of getSelVectorShared.
@github-actions

Copy link
Copy Markdown

Benchmark Result

Master commit hash: ebea6632163bf8a16d0dedb7b85b95be6512eed2
Branch commit hash: 57e6f88a6d8303d81eb18ad3f3069c4312ee015c

Query Group Query Name Mean Time - Commit (ms) Mean Time - Master (ms) Diff
aggregation q24 643.01 655.30 -12.29 (-1.87%)
aggregation q28 11824.71 11747.46 77.24 (0.66%)
filter q14 127.98 136.30 -8.32 (-6.11%)
filter q15 124.55 134.87 -10.32 (-7.65%)
filter q16 304.19 311.04 -6.84 (-2.20%)
filter q17 444.04 455.40 -11.36 (-2.50%)
filter q18 1962.90 1918.10 44.80 (2.34%)
filter zonemap-node 87.63 95.56 -7.93 (-8.30%)
filter zonemap-node-lhs-cast 87.06 96.80 -9.74 (-10.06%)
filter zonemap-rel 5400.64 5339.66 60.98 (1.14%)
fixed_size_expr_evaluator q07 571.07 693.73 -122.65 (-17.68%)
fixed_size_expr_evaluator q08 801.64 973.12 -171.48 (-17.62%)
fixed_size_expr_evaluator q09 802.87 970.48 -167.60 (-17.27%)
fixed_size_expr_evaluator q10 235.87 293.23 -57.36 (-19.56%)
fixed_size_expr_evaluator q11 230.51 284.53 -54.03 (-18.99%)
fixed_size_expr_evaluator q12 224.86 266.69 -41.84 (-15.69%)
fixed_size_expr_evaluator q13 1457.86 1679.52 -221.66 (-13.20%)
fixed_size_seq_scan q23 111.35 126.05 -14.71 (-11.67%)
join q29 592.81 577.47 15.33 (2.66%)
join q30 1323.39 1325.38 -2.00 (-0.15%)
join q31 5.56 6.83 -1.26 (-18.48%)
ldbc_snb_ic q35 394.87 410.91 -16.04 (-3.90%)
ldbc_snb_ic q36 125.88 124.27 1.62 (1.30%)
ldbc_snb_is q32 5.54 6.25 -0.71 (-11.36%)
ldbc_snb_is q33 13.33 13.35 -0.02 (-0.13%)
ldbc_snb_is q34 1.63 1.34 0.29 (21.57%)
multi-rel multi-rel-large-scan 1208.69 1595.17 -386.48 (-24.23%)
multi-rel multi-rel-lookup 39.59 5.44 34.15 (628.03%)
multi-rel multi-rel-small-scan 93.59 67.98 25.61 (37.67%)
order_by q25 132.27 146.20 -13.93 (-9.52%)
order_by q26 456.42 468.68 -12.26 (-2.62%)
order_by q27 1452.89 1479.59 -26.70 (-1.80%)
scan_after_filter q01 168.27 180.86 -12.59 (-6.96%)
scan_after_filter q02 156.05 164.30 -8.25 (-5.02%)
shortest_path_ldbc100 q37 87.58 80.40 7.18 (8.93%)
shortest_path_ldbc100 q38 492.69 522.28 -29.58 (-5.66%)
shortest_path_ldbc100 q39 63.27 52.32 10.95 (20.92%)
shortest_path_ldbc100 q40 567.02 381.30 185.72 (48.71%)
var_size_expr_evaluator q03 2039.83 2067.32 -27.49 (-1.33%)
var_size_expr_evaluator q04 2271.57 2231.71 39.86 (1.79%)
var_size_expr_evaluator q05 2586.59 2631.10 -44.51 (-1.69%)
var_size_expr_evaluator q06 1327.34 1338.63 -11.30 (-0.84%)
var_size_seq_scan q19 1441.77 1487.47 -45.70 (-3.07%)
var_size_seq_scan q20 2431.26 2423.15 8.12 (0.33%)
var_size_seq_scan q21 2264.08 2310.57 -46.50 (-2.01%)
var_size_seq_scan q22 127.36 131.78 -4.42 (-3.36%)

@codecov

codecov Bot commented Nov 22, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 88.63636% with 5 lines in your changes missing coverage. Please review.

Project coverage is 87.36%. Comparing base (d12c21f) to head (7b20c24).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
src/common/null_mask.cpp 0.00% 4 Missing ⚠️
src/include/common/vector/value_vector.h 93.33% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4558   +/-   ##
=======================================
  Coverage   87.36%   87.36%           
=======================================
  Files        1349     1349           
  Lines       56587    56601   +14     
  Branches     7079     7068   -11     
=======================================
+ Hits        49436    49451   +15     
+ Misses       6979     6978    -1     
  Partials      172      172           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@github-actions

Copy link
Copy Markdown

Benchmark Result

Master commit hash: ebea6632163bf8a16d0dedb7b85b95be6512eed2
Branch commit hash: a5025a5fd5e352bcf21ba67dd6949d2781992b49

Query Group Query Name Mean Time - Commit (ms) Mean Time - Master (ms) Diff
aggregation q24 655.62 655.30 0.32 (0.05%)
aggregation q28 15325.84 11747.46 3578.38 (30.46%)
copy node-Comment 79757.52 N/A N/A
copy node-Forum 5478.87 N/A N/A
copy node-Organisation 1215.73 N/A N/A
copy node-Person 2157.62 N/A N/A
copy node-Place 1171.60 N/A N/A
copy node-Post 29887.89 N/A N/A
copy node-Tag 1247.88 N/A N/A
copy node-Tagclass 1162.50 N/A N/A
copy rel-comment-hasCreator 64147.15 N/A N/A
copy rel-comment-hasTag 111687.05 N/A N/A
copy rel-comment-isLocatedIn 73406.31 N/A N/A
copy rel-containerOf 14869.64 N/A N/A
copy rel-forum-hasTag 4048.70 N/A N/A
copy rel-hasInterest 3180.09 N/A N/A
copy rel-hasMember 59214.60 N/A N/A
copy rel-hasModerator 1287.40 N/A N/A
copy rel-hasType 233.35 N/A N/A
copy rel-isPartOf 277.15 N/A N/A
copy rel-isSubclassOf 216.81 N/A N/A
copy rel-knows 6581.51 N/A N/A
copy rel-likes-comment 100950.68 N/A N/A
copy rel-likes-post 37947.21 N/A N/A
copy rel-organisation-isLocatedIn 226.73 N/A N/A
copy rel-person-isLocatedIn 416.37 N/A N/A
copy rel-post-hasCreator 15407.47 N/A N/A
copy rel-post-hasTag 23978.62 N/A N/A
copy rel-post-isLocatedIn 19605.61 N/A N/A
copy rel-replyOf-comment 57047.21 N/A N/A
copy rel-replyOf-post 43861.47 N/A N/A
copy rel-studyAt 469.67 N/A N/A
copy rel-workAt 763.38 N/A N/A
filter q14 128.18 136.30 -8.12 (-5.96%)
filter q15 127.99 134.87 -6.89 (-5.11%)
filter q16 306.42 311.04 -4.62 (-1.48%)
filter q17 445.97 455.40 -9.43 (-2.07%)
filter q18 1974.40 1918.10 56.31 (2.94%)
filter zonemap-node 86.94 95.56 -8.62 (-9.02%)
filter zonemap-node-lhs-cast 87.23 96.80 -9.56 (-9.88%)
filter zonemap-rel 5429.36 5339.66 89.70 (1.68%)
fixed_size_expr_evaluator q07 610.79 693.73 -82.94 (-11.96%)
fixed_size_expr_evaluator q08 800.42 973.12 -172.70 (-17.75%)
fixed_size_expr_evaluator q09 814.37 970.48 -156.11 (-16.09%)
fixed_size_expr_evaluator q10 240.31 293.23 -52.92 (-18.05%)
fixed_size_expr_evaluator q11 232.38 284.53 -52.16 (-18.33%)
fixed_size_expr_evaluator q12 229.49 266.69 -37.21 (-13.95%)
fixed_size_expr_evaluator q13 1481.48 1679.52 -198.03 (-11.79%)
fixed_size_seq_scan q23 115.52 126.05 -10.54 (-8.36%)
join q29 623.58 577.47 46.11 (7.98%)
join q30 1356.71 1325.38 31.33 (2.36%)
join q31 6.62 6.83 -0.21 (-3.01%)
ldbc_snb_ic q35 382.13 410.91 -28.77 (-7.00%)
ldbc_snb_ic q36 131.24 124.27 6.98 (5.62%)
ldbc_snb_is q32 4.66 6.25 -1.58 (-25.33%)
ldbc_snb_is q33 14.81 13.35 1.46 (10.96%)
ldbc_snb_is q34 1.40 1.34 0.07 (4.88%)
multi-rel multi-rel-large-scan 1189.93 1595.17 -405.24 (-25.40%)
multi-rel multi-rel-lookup 46.56 5.44 41.12 (756.12%)
multi-rel multi-rel-small-scan 74.38 67.98 6.39 (9.40%)
order_by q25 141.27 146.20 -4.93 (-3.37%)
order_by q26 457.30 468.68 -11.38 (-2.43%)
order_by q27 1460.90 1479.59 -18.69 (-1.26%)
scan_after_filter q01 167.22 180.86 -13.64 (-7.54%)
scan_after_filter q02 157.04 164.30 -7.26 (-4.42%)
shortest_path_ldbc100 q37 98.46 80.40 18.07 (22.47%)
shortest_path_ldbc100 q38 428.22 522.28 -94.05 (-18.01%)
shortest_path_ldbc100 q39 64.02 52.32 11.70 (22.36%)
shortest_path_ldbc100 q40 542.34 381.30 161.05 (42.24%)
var_size_expr_evaluator q03 2060.11 2067.32 -7.20 (-0.35%)
var_size_expr_evaluator q04 2303.96 2231.71 72.26 (3.24%)
var_size_expr_evaluator q05 2625.83 2631.10 -5.28 (-0.20%)
var_size_expr_evaluator q06 1334.11 1338.63 -4.53 (-0.34%)
var_size_seq_scan q19 1442.12 1487.47 -45.34 (-3.05%)
var_size_seq_scan q20 2447.65 2423.15 24.51 (1.01%)
var_size_seq_scan q21 2284.47 2310.57 -26.11 (-1.13%)
var_size_seq_scan q22 127.74 131.78 -4.04 (-3.07%)

@andyfengHKU
andyfengHKU merged commit 756486b into master Nov 24, 2024
@andyfengHKU
andyfengHKU deleted the rel-scan-selection-opt branch November 24, 2024 14:58
ray6080 pushed a commit that referenced this pull request Dec 18, 2024
* Set the SelectionVector to STATIC_FILTERED when scanning cached rels if possible

bitset access is relatively slow, and may not be necessary
There are also some optimizations possible to take advantage of not having to scan the SelectionVector's buffer (though I'm not sure if we're actually taking advantage of it right now).
And I avoided the unnecessary creation/destruction of a std::shared_ptr in RelTableScanState::setNodeIDVectorToFlat by using getSelVectorUnsafe instead of getSelVectorShared.

* Optimize some operator code

* Removed an unnecessary std::shared_ptr copy
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants