-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[branch-4.1][fix](be) Preserve nested paths for lazy rowid fetch #65260
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
Open
mrhhsg
wants to merge
2
commits into
apache:branch-4.1
Choose a base branch
from
mrhhsg:backport-64242-branch-4.1
base: branch-4.1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
...java/org/apache/doris/nereids/processor/post/materialize/MaterializeProbeVisitorTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| package org.apache.doris.nereids.processor.post.materialize; | ||
|
|
||
| import org.apache.doris.catalog.KeysType; | ||
| import org.apache.doris.catalog.OlapTable; | ||
| import org.apache.doris.nereids.trees.expressions.SlotReference; | ||
| import org.apache.doris.nereids.trees.plans.physical.PhysicalFilter; | ||
| import org.apache.doris.nereids.trees.plans.physical.PhysicalOlapScan; | ||
| import org.apache.doris.nereids.types.IntegerType; | ||
| import org.apache.doris.qe.ConnectContext; | ||
| import org.apache.doris.thrift.TAccessPathType; | ||
| import org.apache.doris.thrift.TColumnAccessPath; | ||
| import org.apache.doris.thrift.TDataAccessPath; | ||
|
|
||
| import com.google.common.collect.ImmutableList; | ||
| import com.google.common.collect.ImmutableSet; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.mockito.Mockito; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| public class MaterializeProbeVisitorTest { | ||
|
|
||
| @Test | ||
| public void testOlapScanUsesRelationSlotWithAccessPaths() { | ||
| SlotReference contextSlot = new SlotReference("a", IntegerType.INSTANCE); | ||
| SlotReference relationSlot = contextSlot.withAccessPaths( | ||
| ImmutableList.of(dataPath("nested")), ImmutableList.of()); | ||
| contextSlot = (SlotReference) contextSlot.withNullable(false); | ||
| PhysicalOlapScan scan = mockBaseOlapScan(relationSlot); | ||
|
|
||
| MaterializeProbeVisitor.ProbeContext context = new MaterializeProbeVisitor.ProbeContext(contextSlot); | ||
| Optional<MaterializeSource> source = new MaterializeProbeVisitor().visitPhysicalOlapScan(scan, context); | ||
|
|
||
| Assertions.assertTrue(source.isPresent()); | ||
| Assertions.assertSame(relationSlot, source.get().baseSlot); | ||
| Assertions.assertEquals(relationSlot.getAllAccessPaths(), source.get().baseSlot.getAllAccessPaths()); | ||
| } | ||
|
|
||
| @Test | ||
| @SuppressWarnings("unchecked") | ||
| public void testFilterUsingIndexUsesRelationSlotWithAccessPaths() { | ||
| ConnectContext oldContext = ConnectContext.get(); | ||
| ConnectContext context = new ConnectContext(); | ||
| context.getSessionVariable().topNLazyMaterializationUsingIndex = true; | ||
| context.setThreadLocalInfo(); | ||
| try { | ||
| SlotReference contextSlot = new SlotReference("a", IntegerType.INSTANCE); | ||
| SlotReference relationSlot = contextSlot.withAccessPaths( | ||
| ImmutableList.of(dataPath("nested")), ImmutableList.of()); | ||
| contextSlot = (SlotReference) contextSlot.withNullable(false); | ||
| PhysicalOlapScan scan = mockBaseOlapScan(relationSlot); | ||
|
|
||
| PhysicalFilter<PhysicalOlapScan> filter = Mockito.mock(PhysicalFilter.class); | ||
| Mockito.when(filter.child()).thenReturn(scan); | ||
| Mockito.when(filter.getInputSlots()).thenReturn(ImmutableSet.of(contextSlot)); | ||
|
|
||
| MaterializeProbeVisitor.ProbeContext probeContext = new MaterializeProbeVisitor.ProbeContext(contextSlot); | ||
| Optional<MaterializeSource> source = | ||
| new MaterializeProbeVisitor().visitPhysicalFilter(filter, probeContext); | ||
|
|
||
| Assertions.assertTrue(source.isPresent()); | ||
| Assertions.assertSame(relationSlot, source.get().baseSlot); | ||
| Assertions.assertEquals(relationSlot.getAllAccessPaths(), source.get().baseSlot.getAllAccessPaths()); | ||
| } finally { | ||
| if (oldContext == null) { | ||
| ConnectContext.remove(); | ||
| } else { | ||
| oldContext.setThreadLocalInfo(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private TColumnAccessPath dataPath(String... path) { | ||
| TColumnAccessPath accessPath = new TColumnAccessPath(TAccessPathType.DATA); | ||
| accessPath.data_access_path = new TDataAccessPath(ImmutableList.copyOf(path)); | ||
| return accessPath; | ||
| } | ||
|
|
||
| private PhysicalOlapScan mockBaseOlapScan(SlotReference outputSlot) { | ||
| OlapTable table = Mockito.mock(OlapTable.class); | ||
| Mockito.when(table.getBaseIndexId()).thenReturn(1L); | ||
| Mockito.when(table.getKeysType()).thenReturn(KeysType.DUP_KEYS); | ||
| PhysicalOlapScan scan = Mockito.mock(PhysicalOlapScan.class); | ||
| Mockito.when(scan.getSelectedIndexId()).thenReturn(1L); | ||
| Mockito.when(scan.getTable()).thenReturn(table); | ||
| Mockito.when(scan.getOutput()).thenReturn(ImmutableList.of(outputSlot)); | ||
| Mockito.when(scan.getOperativeSlots()).thenReturn(ImmutableList.of()); | ||
| return scan; | ||
| } | ||
| } |
42 changes: 42 additions & 0 deletions
42
regression-test/data/nereids_rules_p0/column_pruning/topn_lazy_nested_column_pruning.out
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| -- This file is automatically generated. You should know what you did if you want to edit this | ||
| -- !struct_result -- | ||
| 1 \N | ||
|
|
||
| -- !variant_result -- | ||
| 1 aaa 张三 | ||
| 2 bbb 李四 | ||
| 3 ccc 王五 | ||
|
|
||
| -- !map_result -- | ||
| 1 1 | ||
|
|
||
| -- !array_result -- | ||
| 1 1 | ||
|
|
||
| -- !variant_nested_result -- | ||
| 4 上海 | ||
| 5 北京 | ||
|
|
||
| -- !map_using_index_result -- | ||
| 1 1 | ||
|
|
||
| -- !array_using_index_result -- | ||
| 1 1 | ||
|
|
||
| -- !struct_col_order_result -- | ||
| \N 1 | ||
|
|
||
| -- !variant_col_order_result -- | ||
| 张三 1 aaa | ||
| 李四 2 bbb | ||
| 王五 3 ccc | ||
|
|
||
| -- !map_col_order_result -- | ||
| 1 1 | ||
|
|
||
| -- !project_under_topn_consumed_slot -- | ||
| 1 hello {"city":null, "zip":10001} [1, 2, 3] {"a":1, "b":2} 1 \N | ||
|
|
||
| -- !sparse_struct_map_array_result -- | ||
| 3 9 9 3 false | ||
| 1 7 7 3 false |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still does not get the nested access paths to BE. The visitor now returns the relation output slot, but the slot that becomes the materialization tuple descriptor is rebuilt later from the original lazy slot:
PhysicalLazyMaterializedoes((SlotReference) lazySlot).withColumn(originalColumn), andwithColumn()does not copyallAccessPaths/predicateAccessPaths.generateTupleDesc(materialize.getOutput(), ...)therefore creates aSlotDescriptorwith empty access paths, so the newset_slot_access_paths()calls in BE are a no-op for the targeted rowid fetch. Please carryMaterializeSource.baseSlot's access paths onto the lazy output slot that is serialized for the fetch request, and add a test that checks the materialization tuple descriptor contains those paths.