Skip to content

Commit 65908ea

Browse files
fix custom type compare bug (#64)
1 parent b79fb2f commit 65908ea

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

storage/temptable/include/temptable/cell_calculator.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,14 @@ inline int Cell_calculator::compare(const Cell &lhs, const Cell &rhs) const {
291291
/* Note: Using if-s instead of switch due to bug mentioned in hash(). */
292292

293293
if (m_mode == Mode::BINARY) {
294+
// VillageSQL: cell data is raw (no length prefix), so call
295+
// TryCompareCustomType directly instead of key_cmp which expects a
296+
// 2-byte length-prefixed key image.
297+
auto result = villagesql::TryCompareCustomType(
298+
m_mysql_field, lhs_data, lhs_data_length, rhs_data, rhs_data_length);
299+
if (result.has_value()) {
300+
return result.value();
301+
}
294302
return const_cast<Field *>(m_mysql_field)->key_cmp(lhs_data, rhs_data);
295303
} else if (m_mode == Mode::CHARSET) {
296304
lhs_length = lhs_data_length;

villagesql/examples/vsql-complex/src/complex.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include <villagesql/extension.h>
3030

31+
#include <cassert>
3132
#include <cmath>
3233
#include <cstddef>
3334
#include <cstdint>
@@ -180,6 +181,7 @@ bool decode_complex(const unsigned char *buffer, size_t buffer_size, char *to,
180181
int cmp_complex(const unsigned char *data1, size_t len1,
181182
const unsigned char *data2, size_t len2) {
182183
if (len1 < kComplexSize || len2 < kComplexSize) {
184+
assert(len1 != 0);
183185
return 0; // Invalid lengths, treat as equal
184186
}
185187

0 commit comments

Comments
 (0)