@@ -1100,77 +1100,6 @@ static inline enum REC_INSERT_STATE rec_init_null_and_len_comp(
1100
1100
return (rec_insert_state);
1101
1101
}
1102
1102
1103
- /* *
1104
- Determine the offset of the given field
1105
-
1106
- @param[in] field Field whose length and offset is determined
1107
- @param[in] index Index to which field belongs
1108
- @param[in] temp True for temp record
1109
- @param[in,out] n_null Number of nullable columns in record
1110
- @param[in,out] null_mask Mask of null bitmap
1111
- @param[in,out] nulls Pointer to null bitmap of the record
1112
- @param[in,out] lens Pointer to lens in the record
1113
- @param[in,out] offs Offset of current field, updated to next field
1114
- @param[in,out] any_ext Offset to indicate presence of extern col
1115
-
1116
- @return offset Offset of the field
1117
- */
1118
- static inline uint64_t calculate_field_offset (
1119
- const dict_field_t *field,
1120
- IF_DEBUG (const dict_index_t *index, ) const bool temp, uint16_t &n_null,
1121
- ulint &null_mask, const byte *&nulls, const byte *&lens, ulint &offs,
1122
- ulint &any_ext) {
1123
- /* Fields are stored on disk in version they are added in and are maintained
1124
- in fields_array in the same order. Get the right field. */
1125
- const dict_col_t *col = field->col ;
1126
-
1127
- if (!(col->prtype & DATA_NOT_NULL)) {
1128
- /* nullable field => read the null flag */
1129
- ut_ad (n_null--);
1130
-
1131
- if (UNIV_UNLIKELY (!(byte)null_mask)) {
1132
- nulls--;
1133
- null_mask = 1 ;
1134
- }
1135
-
1136
- if (*nulls & null_mask) {
1137
- null_mask <<= 1 ;
1138
- /* No length is stored for NULL fields. We do not advance offs, and we set
1139
- the length to zero and enable the SQL NULL flag in offsets[]. */
1140
- return (offs | REC_OFFS_SQL_NULL);
1141
- }
1142
- null_mask <<= 1 ;
1143
- }
1144
-
1145
- if (!field->fixed_len || (temp && !col->get_fixed_size (temp))) {
1146
- ut_ad (col->mtype != DATA_POINT);
1147
- /* Variable-length field: read the length */
1148
- uint64_t len = *lens--;
1149
- /* If the maximum length of the field is up to 255 bytes, the actual length
1150
- is always stored in one byte. If the maximum length is more than 255 bytes,
1151
- the actual length is stored in one byte for 0..127. The length will be
1152
- encoded in two bytes when it is 128 or more, or when the field is stored
1153
- externally. */
1154
- if (DATA_BIG_COL (col)) {
1155
- if (len & 0x80 ) {
1156
- /* 1exxxxxxx xxxxxxxx */
1157
- len <<= 8 ;
1158
- len |= *lens--;
1159
-
1160
- offs += len & 0x3fff ;
1161
- if (UNIV_UNLIKELY (len & 0x4000 )) {
1162
- ut_ad (index->is_clustered ());
1163
- any_ext = REC_OFFS_EXTERNAL;
1164
- return (offs | REC_OFFS_EXTERNAL);
1165
- }
1166
- return offs;
1167
- }
1168
- }
1169
- return (offs += len);
1170
- }
1171
- return (offs += field->fixed_len );
1172
- }
1173
-
1174
1103
/* * Determine the offset to each field in a leaf-page record in
1175
1104
ROW_FORMAT=COMPACT. This is a special case of rec_init_offsets() and
1176
1105
rec_get_offsets().
@@ -1229,34 +1158,25 @@ inline void rec_init_offsets_comp_ordinary(const rec_t *rec, bool temp,
1229
1158
ulint any_ext = 0 ;
1230
1159
ulint null_mask = 1 ;
1231
1160
uint16_t i = 0 ;
1232
-
1233
- if (rec_insert_state == INSERTED_INTO_TABLE_WITH_NO_INSTANT_NO_VERSION) {
1234
- ut_ad (!index->has_instant_cols_or_row_versions ());
1235
- do {
1236
- const dict_field_t *field = index->get_physical_field (i);
1237
- rec_offs_base (offsets)[i + 1 ] =
1238
- calculate_field_offset (field, IF_DEBUG (index, ) temp, n_null,
1239
- null_mask, nulls, lens, offs, any_ext);
1240
- } while (++i < rec_offs_n_fields (offsets));
1241
-
1242
- *rec_offs_base (offsets) = (rec - (lens + 1 )) | REC_OFFS_COMPACT | any_ext;
1243
- return ;
1244
- }
1245
-
1246
- /* This record belongs to a table which has at least one INSTANT ADD/DROP done
1247
- */
1248
- if (rec_insert_state == INSERTED_BEFORE_INSTANT_ADD_NEW_IMPLEMENTATION) {
1249
- ut_ad (row_version == UINT8_UNDEFINED || row_version == 0 );
1250
- ut_ad (index->has_row_versions () || temp);
1251
- /* Record has to be interpreted in v0. */
1252
- row_version = 0 ;
1253
- }
1254
-
1255
1161
do {
1162
+ /* Fields are stored on disk in version they are added in and are
1163
+ maintained in fields_array in the same order. Get the right field. */
1256
1164
const dict_field_t *field = index->get_physical_field (i);
1257
1165
const dict_col_t *col = field->col ;
1166
+ uint64_t len;
1167
+
1258
1168
switch (rec_insert_state) {
1259
- case INSERTED_BEFORE_INSTANT_ADD_NEW_IMPLEMENTATION:
1169
+ case INSERTED_INTO_TABLE_WITH_NO_INSTANT_NO_VERSION:
1170
+ ut_ad (!index->has_instant_cols_or_row_versions ());
1171
+ break ;
1172
+
1173
+ case INSERTED_BEFORE_INSTANT_ADD_NEW_IMPLEMENTATION: {
1174
+ ut_ad (row_version == UINT8_UNDEFINED || row_version == 0 );
1175
+ ut_ad (index->has_row_versions () || temp);
1176
+ /* Record has to be interpreted in v0. */
1177
+ row_version = 0 ;
1178
+ }
1179
+ [[fallthrough]];
1260
1180
case INSERTED_AFTER_UPGRADE_BEFORE_INSTANT_ADD_NEW_IMPLEMENTATION:
1261
1181
case INSERTED_AFTER_INSTANT_ADD_NEW_IMPLEMENTATION: {
1262
1182
ut_ad (is_valid_row_version (row_version));
@@ -1268,22 +1188,21 @@ inline void rec_init_offsets_comp_ordinary(const rec_t *rec, bool temp,
1268
1188
column is there in this record or not. */
1269
1189
if (col->is_dropped_in_or_before (row_version)) {
1270
1190
/* This columns is dropped before or on this row version so its data
1271
- won't be there on row. So no need to store the length. Instead,
1272
- store offs ORed with REC_OFFS_DROP to indicate the same. */
1273
- rec_offs_base (offsets)[i + 1 ] = (offs | REC_OFFS_DROP);
1274
- continue ;
1275
-
1276
- /* NOTE : Existing rows, which have data for this column, would
1277
- still need to process this column, so don't skip and store the
1278
- correct length there. Though it will be skipped while fetching row.
1279
- */
1191
+ won't be there on row. So no need to store the length. Instead, store
1192
+ offs ORed with REC_OFFS_DROP to indicate the same. */
1193
+ len = offs | REC_OFFS_DROP;
1194
+ goto resolved;
1195
+
1196
+ /* NOTE : Existing rows, which have data for this column, would still
1197
+ need to process this column, so don't skip and store the correct
1198
+ length there. Though it will be skipped while fetching row. */
1280
1199
} else if (col->is_added_after (row_version)) {
1281
- /* This columns is added after this row version. In this case no
1282
- need to store the length. Instead store only if it is NULL or
1283
- DEFAULT value. */
1284
- rec_offs_base (offsets)[i + 1 ] =
1285
- rec_get_instant_offset (index, i, offs);
1286
- continue ;
1200
+ /* This columns is added after this row version. In this case no need
1201
+ to store the length. Instead store only if it is NULL or DEFAULT
1202
+ value. */
1203
+ len = rec_get_instant_offset (index, i, offs);
1204
+
1205
+ goto resolved ;
1287
1206
}
1288
1207
} break ;
1289
1208
@@ -1297,9 +1216,9 @@ inline void rec_init_offsets_comp_ordinary(const rec_t *rec, bool temp,
1297
1216
/* This would be the case when column doesn't exists in the row. In
1298
1217
this case we need not to store the length. Instead we store only if
1299
1218
the column is NULL or DEFAULT value. */
1300
- rec_offs_base (offsets)[i + 1 ] =
1301
- rec_get_instant_offset (index, i, offs);
1302
- continue ;
1219
+ len = rec_get_instant_offset (index, i, offs);
1220
+
1221
+ goto resolved ;
1303
1222
}
1304
1223
1305
1224
/* Note : Even if the column has been dropped, this row in V1 would
@@ -1309,9 +1228,64 @@ inline void rec_init_offsets_comp_ordinary(const rec_t *rec, bool temp,
1309
1228
default :
1310
1229
ut_ad (false );
1311
1230
}
1312
- rec_offs_base (offsets)[i + 1 ] =
1313
- calculate_field_offset (field, IF_DEBUG (index, ) temp, n_null, null_mask,
1314
- nulls, lens, offs, any_ext);
1231
+
1232
+ if (!(col->prtype & DATA_NOT_NULL)) {
1233
+ /* nullable field => read the null flag */
1234
+ ut_ad (n_null--);
1235
+
1236
+ if (UNIV_UNLIKELY (!(byte)null_mask)) {
1237
+ nulls--;
1238
+ null_mask = 1 ;
1239
+ }
1240
+
1241
+ if (*nulls & null_mask) {
1242
+ null_mask <<= 1 ;
1243
+ /* No length is stored for NULL fields.
1244
+ We do not advance offs, and we set
1245
+ the length to zero and enable the
1246
+ SQL NULL flag in offsets[]. */
1247
+ len = offs | REC_OFFS_SQL_NULL;
1248
+ goto resolved;
1249
+ }
1250
+ null_mask <<= 1 ;
1251
+ }
1252
+
1253
+ if (!field->fixed_len || (temp && !col->get_fixed_size (temp))) {
1254
+ ut_ad (col->mtype != DATA_POINT);
1255
+ /* Variable-length field: read the length */
1256
+ len = *lens--;
1257
+ /* If the maximum length of the field is up
1258
+ to 255 bytes, the actual length is always
1259
+ stored in one byte. If the maximum length is
1260
+ more than 255 bytes, the actual length is
1261
+ stored in one byte for 0..127. The length
1262
+ will be encoded in two bytes when it is 128 or
1263
+ more, or when the field is stored externally. */
1264
+ if (DATA_BIG_COL (col)) {
1265
+ if (len & 0x80 ) {
1266
+ /* 1exxxxxxx xxxxxxxx */
1267
+ len <<= 8 ;
1268
+ len |= *lens--;
1269
+
1270
+ offs += len & 0x3fff ;
1271
+ if (UNIV_UNLIKELY (len & 0x4000 )) {
1272
+ ut_ad (index->is_clustered ());
1273
+ any_ext = REC_OFFS_EXTERNAL;
1274
+ len = offs | REC_OFFS_EXTERNAL;
1275
+ } else {
1276
+ len = offs;
1277
+ }
1278
+
1279
+ goto resolved;
1280
+ }
1281
+ }
1282
+
1283
+ len = offs += len;
1284
+ } else {
1285
+ len = offs += field->fixed_len ;
1286
+ }
1287
+ resolved:
1288
+ rec_offs_base (offsets)[i + 1 ] = len;
1315
1289
} while (++i < rec_offs_n_fields (offsets));
1316
1290
1317
1291
*rec_offs_base (offsets) = (rec - (lens + 1 )) | REC_OFFS_COMPACT | any_ext;
0 commit comments