Skip to content

Commit 1e27e0f

Browse files
committed
hash match
1 parent f7971fc commit 1e27e0f

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

src/query/expression/src/aggregate/hash_index.rs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use std::fmt::Debug;
16+
1517
use super::payload_row::CompareState;
1618
use super::CompareItem;
1719
use super::PartitionedPayload;
@@ -96,7 +98,7 @@ const SALT_MASK: u64 = 0xFFFF000000000000;
9698
const POINTER_MASK: u64 = 0x0000FFFFFFFFFFFF;
9799

98100
// The high 16 bits are the salt, the low 48 bits are the pointer address
99-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
101+
#[derive(Clone, Copy, PartialEq, Eq, Default)]
100102
pub(super) struct Entry(pub(super) u64);
101103

102104
impl Entry {
@@ -135,6 +137,15 @@ impl Entry {
135137
}
136138
}
137139

140+
impl Debug for Entry {
141+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
142+
f.debug_tuple("Entry")
143+
.field(&self.get_salt())
144+
.field(&self.get_pointer())
145+
.finish()
146+
}
147+
}
148+
138149
pub(super) trait TableAdapter {
139150
fn append_rows(&mut self, state: &mut ProbeState, new_entry_count: usize);
140151

@@ -256,8 +267,25 @@ impl<'a> TableAdapter for AdapterImpl<'a> {
256267
&mut self,
257268
state: &mut ProbeState,
258269
need_compare_count: usize,
259-
no_match_count: usize,
270+
mut no_match_count: usize,
260271
) -> usize {
272+
let mut count = 0;
273+
for i in 0..need_compare_count {
274+
let item = &state.group_compare_vector[i];
275+
if state.group_hashes[item.row] == item.row_ptr.hash(&self.payload.row_layout) {
276+
if i != count {
277+
state.group_compare_vector[count] = item.clone();
278+
}
279+
count += 1;
280+
} else {
281+
state.no_match_vector[no_match_count] = item.clone();
282+
no_match_count += 1;
283+
}
284+
}
285+
if count == 0 {
286+
return no_match_count;
287+
}
288+
261289
CompareState {
262290
compare: &mut state.group_compare_vector,
263291
matched: &mut state.match_vector,
@@ -266,7 +294,7 @@ impl<'a> TableAdapter for AdapterImpl<'a> {
266294
.row_match_columns(
267295
self.group_columns,
268296
&self.payload.row_layout,
269-
(need_compare_count, no_match_count),
297+
(count, no_match_count),
270298
)
271299
}
272300
}

0 commit comments

Comments
 (0)