Skip to content

Commit a40c233

Browse files
Remove alt buffer handling
1 parent 125ea81 commit a40c233

3 files changed

Lines changed: 15 additions & 30 deletions

File tree

sql/field.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,6 +1889,7 @@ class Field {
18891889
const uchar *unpack_int64(uchar *to, const uchar *from) const;
18901890

18911891
private:
1892+
// TODO(villagesql): Collapse these into one object (here and in Field)
18921893
const villagesql::TypeContext *custom_type{nullptr};
18931894
villagesql::TypeEncoder *type_encoder_{nullptr};
18941895

villagesql/types/type_encoder.cc

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -79,48 +79,35 @@ String *TypeEncoder::encode(const String &from, bool &is_valid) {
7979
vdf_->vdf(&ctx_, &vdf_args_, &vdf_result_);
8080

8181
if (vdf_result_.type != VEF_RESULT_VALUE) {
82-
// TODO(villagesql-beta): handle errors
82+
// TODO(villagesql-beta): log warnings for errors
8383
is_valid = false;
8484
return nullptr;
8585
}
8686

87-
const size_t actual_len = vdf_result_.actual_len;
88-
8987
if (alt_bin_buf_ != nullptr) {
90-
// VDF used its own buffer (output exceeded buffer_size_). Grow
91-
// overflow_buf_ if needed and reuse it across rows.
92-
if (actual_len > overflow_buf_size_) {
93-
auto *new_buf = new (mem_root_) uchar[actual_len];
94-
if (should_assert_if_null(new_buf)) {
95-
my_error(ER_OUTOFMEMORY, MYF(ME_FATALERROR), actual_len);
96-
return nullptr;
97-
}
98-
overflow_buf_ = new_buf;
99-
overflow_buf_size_ = actual_len;
100-
}
101-
if (actual_len > 0) memcpy(overflow_buf_, alt_bin_buf_, actual_len);
102-
overflow_result_.set(pointer_cast<const char *>(overflow_buf_),
103-
actual_len, &my_charset_bin);
104-
return &overflow_result_;
88+
// TODO(villagesql-beta): support the extension returning alternate buffers
89+
is_valid = false;
90+
return nullptr;
10591
}
10692

10793
// TODO(villagesql-beta): report an error or warning when the VDF overruns
108-
// the buffer rather than silently returning invalid.
109-
if (should_assert_if_false(actual_len <= buffer_size_)) {
94+
// the buffer rather than silently returning invalid
95+
const size_t actual_len = vdf_result_.actual_len;
96+
if (actual_len > buffer_size_) {
11097
is_valid = false;
11198
return nullptr;
11299
}
100+
113101
result_.set(buffer_, actual_len, &my_charset_bin);
114102
} else {
103+
// TODO(villagesql-beta): Remove suport for these raw functions
115104
assert(fn_ != nullptr);
116105
size_t actual_length = 0;
117106
if (fn_(pointer_cast<uchar *>(buffer_), buffer_size_, from.ptr(),
118107
from.length(), &actual_length)) {
119108
is_valid = false;
120109
return nullptr;
121110
}
122-
// TODO(villagesql-beta): report an error or warning when the fn_ overruns
123-
// the buffer rather than silently returning invalid.
124111
if (should_assert_if_false(actual_length <= buffer_size_)) {
125112
is_valid = false;
126113
return nullptr;

villagesql/types/util.cc

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,11 @@ bool HandleCustomColumnsForTableRename(THD &thd, const char *old_db,
245245
// the Field clone that caches the encoder pointer, so both are freed together
246246
// when the TABLE is evicted from the table open cache.
247247
//
248-
// For any kind of tmp table we use TABLE_SHARE::mem_root. TABLE::mem_root is
249-
// asserted empty by close_tmp_table() so it cannot be used. thd->mem_root
250-
// (the statement arena) is also wrong: the first TABLE's Fields happen to live
251-
// there for INTERNAL_TMP_TABLE, but additional TABLE instances sharing the
252-
// same TABLE_SHARE (opened via open_table_from_share()) have their cloned
253-
// Fields in share->mem_root, which outlives the statement. TABLE_SHARE::mem_root
254-
// therefore covers all cases and is freed by free_tmp_table() when the table
255-
// is torn down.
248+
// For any kind of tmp table use TABLE_SHARE::mem_root, this is where the
249+
// Fields are allocated for most uses of tmp tables. The one exception is
250+
// INTERNAL_TMP_TABLE where the initial Table object's fields are allocated
251+
// from the THD::mem_root, but for these tables the share is destroyed at the
252+
// end of the statement, so the lifetime is correct.
256253
static TypeEncoder *GetTypeEncoderFor(Field *field) {
257254
TypeEncoder *encoder = field->get_type_encoder();
258255
if (encoder == nullptr) {

0 commit comments

Comments
 (0)