Skip to content

Commit 871db28

Browse files
gurusamidahlerlend
authored andcommitted
Bug#37642186 InnoDB Bulk Load: When vector is stored externally validation errors are reported incorrectly
When VECTOR data is stored externally, the validation routines are incorrectly called on the blob reference. Call the validation routines of vector data at different places for vector data depending on how the data is stored - inline or external. Change-Id: Iad53b9f40693c6d90763bfa6a57437184ab45e7b
1 parent 432d47e commit 871db28

File tree

1 file changed

+44
-48
lines changed

1 file changed

+44
-48
lines changed

sql/server_component/bulk_data_service.cc

Lines changed: 44 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -174,54 +174,6 @@ static int format_blob_column(Field *field, const CHARSET_INFO *from_cs,
174174
break;
175175
}
176176

177-
if (sql_col.m_type == MYSQL_TYPE_VECTOR) {
178-
const size_t len = text_col.m_data_len;
179-
180-
uint32 input_dims = get_dimensions(len, Field_vector::precision);
181-
if (input_dims > Field_vector::max_dimensions) {
182-
error_details.m_column_length = len;
183-
error_details.column_input_data = text_col.m_data_ptr;
184-
return ER_TO_VECTOR_CONVERSION;
185-
}
186-
187-
assert(input_dims != 0);
188-
189-
/* Refer to Item_func_from_vector::per_value_chars */
190-
const uint32 per_value_chars = 16;
191-
uint32 out_length = input_dims * per_value_chars;
192-
193-
#ifndef NDEBUG
194-
const uint32 max_output_bytes =
195-
(Field_vector::max_dimensions * per_value_chars);
196-
assert(out_length <= max_output_bytes);
197-
#endif /* NDEBUG */
198-
199-
if (text_col.m_data_len > sql_col.m_data_len) {
200-
error_details.m_column_length = sql_col.m_data_len;
201-
return ER_TOO_BIG_FIELDLENGTH;
202-
}
203-
204-
/* Refer to Field_vector::store(). */
205-
const char *from = text_col.m_data_ptr;
206-
for (uint32 i = 0; i < input_dims; i++) {
207-
float to_store = 0;
208-
memcpy(&to_store, from + sizeof(float) * i, sizeof(float));
209-
if (std::isnan(to_store) || std::isinf(to_store)) {
210-
error_details.m_column_length = len;
211-
error_details.column_input_data = text_col.m_data_ptr;
212-
return ER_TO_VECTOR_CONVERSION;
213-
}
214-
}
215-
216-
auto ptr = std::make_unique<char[]>(out_length);
217-
if (from_vector_to_string(text_col.m_data_ptr, input_dims, ptr.get(),
218-
&out_length)) {
219-
error_details.m_column_length = len;
220-
error_details.column_input_data = text_col.m_data_ptr;
221-
return ER_TO_VECTOR_CONVERSION;
222-
}
223-
}
224-
225177
char *field_begin = sql_col.get_data();
226178
char *field_data = field_begin + length_size;
227179

@@ -238,6 +190,50 @@ static int format_blob_column(Field *field, const CHARSET_INFO *from_cs,
238190
const size_t nchars = text_col.m_data_len;
239191
auto field_size = sql_col.m_data_len;
240192

193+
if (sql_col.m_type == MYSQL_TYPE_VECTOR) {
194+
assert(!text_col.is_ext());
195+
const size_t len = text_col.m_data_len;
196+
197+
uint32 input_dims = get_dimensions(len, Field_vector::precision);
198+
if (input_dims > Field_vector::max_dimensions) {
199+
error_details.m_column_length = len;
200+
error_details.column_input_data = text_col.m_data_ptr;
201+
return ER_TO_VECTOR_CONVERSION;
202+
}
203+
204+
assert(input_dims != 0);
205+
206+
/* Refer to Item_func_from_vector::per_value_chars */
207+
const uint32 per_value_chars = 16;
208+
uint32 out_length = input_dims * per_value_chars;
209+
210+
#ifndef NDEBUG
211+
const uint32 max_output_bytes =
212+
(Field_vector::max_dimensions * per_value_chars);
213+
assert(out_length <= max_output_bytes);
214+
#endif /* NDEBUG */
215+
216+
/* Refer to Field_vector::store(). */
217+
const char *from = text_col.m_data_ptr;
218+
for (uint32 i = 0; i < input_dims; i++) {
219+
float to_store = 0;
220+
memcpy(&to_store, from + sizeof(float) * i, sizeof(float));
221+
if (std::isnan(to_store) || std::isinf(to_store)) {
222+
error_details.m_column_length = len;
223+
error_details.column_input_data = text_col.m_data_ptr;
224+
return ER_TO_VECTOR_CONVERSION;
225+
}
226+
}
227+
228+
auto ptr = std::make_unique<char[]>(out_length);
229+
if (from_vector_to_string(text_col.m_data_ptr, input_dims, ptr.get(),
230+
&out_length)) {
231+
error_details.m_column_length = len;
232+
error_details.column_input_data = text_col.m_data_ptr;
233+
return ER_TO_VECTOR_CONVERSION;
234+
}
235+
}
236+
241237
if (field_charset == &my_charset_bin) {
242238
/* If the charset of the field is binary, then the column data in the CSV
243239
would also be binary. Don't do any charset conversions. */

0 commit comments

Comments
 (0)