147 UNIV_INTERN ulint rec_dummy;
180 if (n == ULINT_UNDEFINED) {
184 nulls = rec - (REC_N_NEW_EXTRA_BYTES + 1);
193 = dict_index_get_nth_field(index, i);
198 if (!(col->
prtype & DATA_NOT_NULL)) {
201 if (UNIV_UNLIKELY(!(byte) null_mask)) {
206 if (*nulls & null_mask) {
224 if (UNIV_UNLIKELY(col->
len > 255)
225 || UNIV_UNLIKELY(col->
mtype == DATA_BLOB)) {
244 UNIV_INLINE __attribute__((nonnull))
246 rec_init_offsets_comp_ordinary(
260 ulint n_null = index->n_nullable;
261 const byte* nulls = temp
263 : rec - (1 + REC_N_NEW_EXTRA_BYTES);
271 offsets[2] = (ulint) rec;
272 offsets[3] = (ulint) index;
286 = dict_index_get_nth_field(index, i);
291 if (!(col->
prtype & DATA_NOT_NULL)) {
295 if (UNIV_UNLIKELY(!(byte) null_mask)) {
300 if (*nulls & null_mask) {
306 len = offs | REC_OFFS_SQL_NULL;
323 if (UNIV_UNLIKELY(col->
len > 255)
324 || UNIV_UNLIKELY(col->
mtype
331 offs += len & 0x3fff;
332 if (UNIV_UNLIKELY(len
336 any_ext = REC_OFFS_EXTERNAL;
352 rec_offs_base(offsets)[i + 1] = len;
355 *rec_offs_base(offsets)
356 = (rec - (lens + 1)) | REC_OFFS_COMPACT | any_ext;
385 rec_offs_make_valid(rec, index, offsets);
393 ulint n_node_ptr_field = ULINT_UNDEFINED;
395 switch (UNIV_EXPECT(status, REC_STATUS_ORDINARY)) {
396 case REC_STATUS_INFIMUM:
397 case REC_STATUS_SUPREMUM:
399 rec_offs_base(offsets)[0]
400 = REC_N_NEW_EXTRA_BYTES | REC_OFFS_COMPACT;
401 rec_offs_base(offsets)[1] = 8;
403 case REC_STATUS_NODE_PTR:
407 case REC_STATUS_ORDINARY:
408 rec_init_offsets_comp_ordinary(
409 rec,
false, index, offsets);
413 nulls = rec - (REC_N_NEW_EXTRA_BYTES + 1);
421 if (UNIV_UNLIKELY(i == n_node_ptr_field)) {
422 len = offs += REC_NODE_PTR_SIZE;
426 field = dict_index_get_nth_field(index, i);
431 if (UNIV_UNLIKELY(!(byte) null_mask)) {
436 if (*nulls & null_mask) {
442 len = offs | REC_OFFS_SQL_NULL;
462 if (UNIV_UNLIKELY(col->
len > 255)
463 || UNIV_UNLIKELY(col->
mtype
475 ut_a(!(len & 0x4000));
476 offs += len & 0x3fff;
488 rec_offs_base(offsets)[i + 1] = len;
491 *rec_offs_base(offsets)
492 = (rec - (lens + 1)) | REC_OFFS_COMPACT;
495 offs = REC_N_OLD_EXTRA_BYTES;
498 *rec_offs_base(offsets) = offs;
503 offs &= ~REC_1BYTE_SQL_NULL_MASK;
504 offs |= REC_OFFS_SQL_NULL;
506 rec_offs_base(offsets)[1 +
i] = offs;
510 *rec_offs_base(offsets) = offs;
515 offs &= ~REC_2BYTE_SQL_NULL_MASK;
516 offs |= REC_OFFS_SQL_NULL;
519 offs &= ~REC_2BYTE_EXTERN_MASK;
520 offs |= REC_OFFS_EXTERNAL;
521 *rec_offs_base(offsets) |= REC_OFFS_EXTERNAL;
523 rec_offs_base(offsets)[1 +
i] = offs;
559 REC_STATUS_ORDINARY)) {
560 case REC_STATUS_ORDINARY:
563 case REC_STATUS_NODE_PTR:
569 case REC_STATUS_INFIMUM:
570 case REC_STATUS_SUPREMUM:
582 if (UNIV_UNLIKELY(n_fields < n)) {
588 size = n + (1 + REC_OFFS_HEADER_SIZE);
590 if (UNIV_UNLIKELY(!offsets)
592 if (UNIV_UNLIKELY(!*heap)) {
597 offsets =
static_cast<ulint*
>(
603 rec_offs_set_n_fields(offsets, n);
604 rec_init_offsets(rec, index, offsets);
633 ulint n_node_ptr_field;
640 if (UNIV_UNLIKELY(node_ptr)) {
642 n = n_node_ptr_field + 1;
644 n_node_ptr_field = ULINT_UNDEFINED;
649 rec_offs_set_n_fields(offsets, n);
660 if (UNIV_UNLIKELY(i == n_node_ptr_field)) {
661 len = offs += REC_NODE_PTR_SIZE;
665 field = dict_index_get_nth_field(index, i);
669 if (UNIV_UNLIKELY(!(byte) null_mask)) {
674 if (*nulls & null_mask) {
680 len = offs | REC_OFFS_SQL_NULL;
698 if (UNIV_UNLIKELY(col->
len > 255)
699 || UNIV_UNLIKELY(col->
mtype == DATA_BLOB)) {
705 offs += len & 0x3fff;
706 if (UNIV_UNLIKELY(len & 0x4000)) {
707 any_ext = REC_OFFS_EXTERNAL;
708 len = offs | REC_OFFS_EXTERNAL;
722 rec_offs_base(offsets)[i + 1] = len;
725 ut_ad(lens >= extra);
726 *rec_offs_base(offsets) = (lens - extra + REC_N_NEW_EXTRA_BYTES)
727 | REC_OFFS_COMPACT | any_ext;
751 os = rec_1_get_field_start_offs(rec, n);
756 *len = UNIV_SQL_NULL;
761 next_os = next_os & ~REC_1BYTE_SQL_NULL_MASK;
763 os = rec_2_get_field_start_offs(rec, n);
768 *len = UNIV_SQL_NULL;
773 next_os = next_os & ~(REC_2BYTE_SQL_NULL_MASK
779 ut_ad(*len < UNIV_PAGE_SIZE);
787 UNIV_INLINE __attribute__((warn_unused_result, nonnull(1,2)))
789 rec_get_converted_size_comp_prefix_low(
804 ulint n_null = index->n_nullable;
807 ut_ad(!temp || extra);
811 : REC_N_NEW_EXTRA_BYTES
812 + UT_BITS_IN_BYTES(n_null);
822 for (i = 0; i < n_fields; i++) {
828 field = dict_index_get_nth_field(index, i);
832 ut_ad(dict_col_type_assert_equal(col,
833 dfield_get_type(&fields[i])));
843 ut_ad(len <= col->len || col->
mtype == DATA_BLOB
844 || (col->
len == 0 && col->
mtype == DATA_VARCHAR));
847 if (temp && fixed_len
863 ut_ad(len <= fixed_len);
865 ut_ad(!mbmaxlen || len >= mbminlen
866 * (fixed_len / mbmaxlen));
876 || (col->
len < 256 && col->
mtype != DATA_BLOB)) {
892 return(extra_size + data_size);
908 return(rec_get_converted_size_comp_prefix_low(
909 index, fields, n_fields, extra,
false));
931 switch (UNIV_EXPECT(status, REC_STATUS_ORDINARY)) {
932 case REC_STATUS_ORDINARY:
936 case REC_STATUS_NODE_PTR:
940 size = REC_NODE_PTR_SIZE;
942 case REC_STATUS_INFIMUM:
943 case REC_STATUS_SUPREMUM:
945 if (UNIV_LIKELY_NULL(extra)) {
946 *extra = REC_N_NEW_EXTRA_BYTES;
948 return(REC_N_NEW_EXTRA_BYTES + 8);
951 return(ULINT_UNDEFINED);
954 return(size + rec_get_converted_size_comp_prefix_low(
955 index, fields, n_fields, extra,
false));
962 rec_set_nth_field_null_bit(
977 info = info & ~REC_1BYTE_SQL_NULL_MASK;
980 rec_1_set_field_end_info(rec, i, info);
990 info = info & ~REC_2BYTE_SQL_NULL_MASK;
993 rec_2_set_field_end_info(rec, i, info);
1001 rec_set_nth_field_sql_null(
1008 offset = rec_get_field_start_offs(rec, n);
1012 rec_set_nth_field_null_bit(rec, n, TRUE);
1021 rec_convert_dtuple_to_rec_old(
1036 ut_ad(buf && dtuple);
1037 ut_ad(dtuple_validate(dtuple));
1043 ut_ad(n_fields > 0);
1051 memset(buf, 0xff, rec - buf + data_size);
1054 rec_set_n_fields_old(rec, n_fields);
1058 & REC_INFO_BITS_MASK);
1064 if (!n_ext && data_size <= REC_1BYTE_OFFS_LIMIT) {
1068 for (i = 0; i < n_fields; i++) {
1070 field = dtuple_get_nth_field(dtuple, i);
1074 dfield_get_type(field), 0);
1078 ored_offset = end_offset
1084 memcpy(rec + end_offset,
1085 dfield_get_data(field), len);
1088 ored_offset = end_offset;
1091 rec_1_set_field_end_info(rec, i, ored_offset);
1096 for (i = 0; i < n_fields; i++) {
1098 field = dtuple_get_nth_field(dtuple, i);
1102 dfield_get_type(field), 0);
1106 ored_offset = end_offset
1112 memcpy(rec + end_offset,
1113 dfield_get_data(field), len);
1116 ored_offset = end_offset;
1123 rec_2_set_field_end_info(rec, i, ored_offset);
1132 UNIV_INLINE __attribute__((nonnull))
1134 rec_convert_dtuple_to_rec_comp(
1152 ulint n_node_ptr_field;
1154 ulint null_mask = 1;
1158 ut_ad(n_fields > 0);
1161 ut_ad(status == REC_STATUS_ORDINARY);
1163 n_node_ptr_field = ULINT_UNDEFINED;
1171 nulls = rec - (REC_N_NEW_EXTRA_BYTES + 1);
1173 switch (UNIV_EXPECT(status, REC_STATUS_ORDINARY)) {
1174 case REC_STATUS_ORDINARY:
1176 n_node_ptr_field = ULINT_UNDEFINED;
1178 case REC_STATUS_NODE_PTR:
1181 n_node_ptr_field = n_fields - 1;
1183 case REC_STATUS_INFIMUM:
1184 case REC_STATUS_SUPREMUM:
1185 ut_ad(n_fields == 1);
1186 n_node_ptr_field = ULINT_UNDEFINED;
1195 n_null = index->n_nullable;
1198 memset(lens + 1, 0, nulls - lens);
1202 for (i = 0, field = fields; i < n_fields; i++, field++) {
1205 type = dfield_get_type(field);
1208 if (UNIV_UNLIKELY(i == n_node_ptr_field)) {
1210 ut_ad(len == REC_NODE_PTR_SIZE);
1211 memcpy(end, dfield_get_data(field), len);
1212 end += REC_NODE_PTR_SIZE;
1220 if (UNIV_UNLIKELY(!(byte) null_mask)) {
1225 ut_ad(*nulls < null_mask);
1229 *nulls |= null_mask;
1239 ifield = dict_index_get_nth_field(index, i);
1241 if (temp && fixed_len
1253 ulint mbminlen = DATA_MBMINLEN(
1255 ulint mbmaxlen = DATA_MBMAXLEN(
1258 ut_ad(len <= fixed_len);
1259 ut_ad(!mbmaxlen || len >= mbminlen
1260 * (fixed_len / mbmaxlen));
1265 || ifield->
col->
mtype == DATA_BLOB);
1266 ut_ad(len <= REC_ANTELOPE_MAX_INDEX_COL_LEN
1268 *lens-- = (byte) (len >> 8) | 0xc0;
1269 *lens-- = (byte) len;
1273 || !strcmp(index->name,
1274 FTS_INDEX_TABLE_IND_NAME));
1279 *lens-- = (byte) len;
1282 *lens-- = (byte) (len >> 8) | 0x80;
1283 *lens-- = (byte) len;
1287 memcpy(end, dfield_get_data(field), len);
1298 rec_convert_dtuple_to_rec_new(
1312 rec = buf + extra_size;
1314 rec_convert_dtuple_to_rec_comp(
1340 ut_ad(buf && index && dtuple);
1341 ut_ad(dtuple_validate(dtuple));
1345 rec = rec_convert_dtuple_to_rec_new(buf, index, dtuple);
1347 rec = rec_convert_dtuple_to_rec_old(buf, dtuple, n_ext);
1353 ulint offsets_[REC_OFFS_NORMAL_SIZE];
1356 rec_offs_init(offsets_);
1358 offsets = rec_get_offsets(rec, index,
1359 offsets_, ULINT_UNDEFINED, &heap);
1369 if (UNIV_LIKELY_NULL(heap)) {
1377 #ifndef UNIV_HOTBACKUP
1390 return(rec_get_converted_size_comp_prefix_low(
1391 index, fields, n_fields, extra,
true));
1406 rec_init_offsets_comp_ordinary(rec,
true, index, offsets);
1421 rec_convert_dtuple_to_rec_comp(rec, index, fields, n_fields,
1422 REC_STATUS_ORDINARY,
true);
1440 ulint offsets_[REC_OFFS_NORMAL_SIZE];
1441 ulint* offsets = offsets_;
1442 rec_offs_init(offsets_);
1444 offsets = rec_get_offsets(rec, index, offsets, n_fields, &heap);
1452 for (i = 0; i < n_fields; i++) {
1457 field = dtuple_get_nth_field(tuple, i);
1458 data = rec_get_nth_field(rec, offsets, i, &len);
1460 if (len != UNIV_SQL_NULL) {
1476 rec_copy_prefix_to_buf_old(
1490 area_start = REC_N_OLD_EXTRA_BYTES + n_fields;
1492 area_start = REC_N_OLD_EXTRA_BYTES + 2 * n_fields;
1495 prefix_len = area_start + area_end;
1497 if ((*buf == NULL) || (*buf_size < prefix_len)) {
1502 *buf =
static_cast<byte*
>(mem_alloc2(prefix_len, buf_size));
1505 ut_memcpy(*buf, rec - area_start, prefix_len);
1507 copy_rec = *buf + area_start;
1509 rec_set_n_fields_old(copy_rec, n_fields);
1538 UNIV_PREFETCH_RW(*buf);
1541 ut_ad(rec_validate_old(rec));
1542 return(rec_copy_prefix_to_buf_old(
1544 rec_get_field_start_offs(rec, n_fields),
1551 case REC_STATUS_ORDINARY:
1554 case REC_STATUS_NODE_PTR:
1558 case REC_STATUS_INFIMUM:
1559 case REC_STATUS_SUPREMUM:
1566 nulls = rec - (REC_N_NEW_EXTRA_BYTES + 1);
1568 UNIV_PREFETCH_R(lens);
1573 for (i = 0; i < n_fields; i++) {
1577 field = dict_index_get_nth_field(index, i);
1580 if (!(col->
prtype & DATA_NOT_NULL)) {
1582 if (UNIV_UNLIKELY(!(byte) null_mask)) {
1587 if (*nulls & null_mask) {
1598 ulint len = *lens--;
1606 if (col->
len > 255 || col->
mtype == DATA_BLOB) {
1612 UNIV_PREFETCH_R(lens);
1619 UNIV_PREFETCH_R(rec + prefix_len);
1621 prefix_len += rec - (lens + 1);
1623 if ((*buf == NULL) || (*buf_size < prefix_len)) {
1628 *buf =
static_cast<byte*
>(mem_alloc2(prefix_len, buf_size));
1631 memcpy(*buf, lens + 1, prefix_len);
1633 return(*buf + (rec - (lens + 1)));
1656 if ((n_fields == 0) || (n_fields > REC_MAX_N_FIELDS)) {
1657 fprintf(stderr,
"InnoDB: Error: record has %lu fields\n",
1662 for (i = 0; i < n_fields; i++) {
1663 data = rec_get_nth_field_old(rec, i, &len);
1665 if (!((len < UNIV_PAGE_SIZE) || (len == UNIV_SQL_NULL))) {
1667 "InnoDB: Error: record field %lu len %lu\n",
1673 if (len != UNIV_SQL_NULL) {
1675 sum += *(data + len -1);
1686 "InnoDB: Error: record len should be %lu, len %lu\n",
1705 const ulint* offsets)
1717 if ((n_fields == 0) || (n_fields > REC_MAX_N_FIELDS)) {
1718 fprintf(stderr,
"InnoDB: Error: record has %lu fields\n",
1725 for (i = 0; i < n_fields; i++) {
1726 data = rec_get_nth_field(rec, offsets, i, &len);
1728 if (!((len < UNIV_PAGE_SIZE) || (len == UNIV_SQL_NULL))) {
1730 "InnoDB: Error: record field %lu len %lu\n",
1736 if (len != UNIV_SQL_NULL) {
1738 sum += *(data + len -1);
1749 "InnoDB: Error: record len should be %lu, len %lu\n",
1758 ut_a(rec_validate_old(rec));
1782 fprintf(file,
"PHYSICAL RECORD: n_fields %lu;"
1783 " %u-byte offsets; info bits %lu\n",
1788 for (i = 0; i <
n; i++) {
1790 data = rec_get_nth_field_old(rec, i, &len);
1792 fprintf(file,
" %lu:", (ulong) i);
1794 if (len != UNIV_SQL_NULL) {
1801 fprintf(file,
" (total %lu bytes)",
1805 fprintf(file,
" SQL NULL, size %lu ",
1813 rec_validate_old(rec);
1816 #ifndef UNIV_HOTBACKUP
1826 const ulint* offsets)
1834 data = rec_get_nth_field(rec, offsets, i, &len);
1836 fprintf(file,
" %lu:", (ulong) i);
1838 if (len != UNIV_SQL_NULL) {
1844 fprintf(file,
" (total %lu bytes, external)",
1852 fprintf(file,
" (total %lu bytes)",
1856 fputs(
" SQL NULL", file);
1871 const ulint* offsets)
1875 ut_ad(rec_offs_validate(rec, NULL, offsets));
1882 fprintf(file,
"PHYSICAL RECORD: n_fields %lu;"
1883 " compact format; info bits %lu\n",
1908 ulint offsets_[REC_OFFS_NORMAL_SIZE];
1909 rec_offs_init(offsets_);
1912 rec_get_offsets(rec, index, offsets_,
1913 ULINT_UNDEFINED, &heap));
1914 if (UNIV_LIKELY_NULL(heap)) {
1938 ulint offsets_[REC_OFFS_NORMAL_SIZE];
1939 ulint* offsets = offsets_;
1940 rec_offs_init(offsets_);
1946 ut_ad(trx_id_col > 0);
1947 ut_ad(trx_id_col != ULINT_UNDEFINED);
1949 offsets = rec_get_offsets(rec, index, offsets, trx_id_col + 1, &heap);
1951 trx_id = rec_get_nth_field(rec, offsets, trx_id_col, &len);
1953 ut_ad(len == DATA_TRX_ID_LEN);