| 420 | PG_FUNCTION_INFO_V1(tuple_data_split); |
| 421 | |
| 422 | Datum |
| 423 | tuple_data_split(PG_FUNCTION_ARGS) |
| 424 | { |
| 425 | Oid relid; |
| 426 | bytea *raw_data; |
| 427 | uint16 t_infomask; |
| 428 | uint16 t_infomask2; |
| 429 | char *t_bits_str; |
| 430 | bool do_detoast = false; |
| 431 | bits8 *t_bits = NULL; |
| 432 | Datum res; |
| 433 | |
| 434 | relid = PG_GETARG_OID(0); |
| 435 | raw_data = PG_ARGISNULL(1) ? NULL : PG_GETARG_BYTEA_P(1); |
| 436 | t_infomask = PG_GETARG_INT16(2); |
| 437 | t_infomask2 = PG_GETARG_INT16(3); |
| 438 | t_bits_str = PG_ARGISNULL(4) ? NULL : |
| 439 | text_to_cstring(PG_GETARG_TEXT_PP(4)); |
| 440 | |
| 441 | if (PG_NARGS() >= 6) |
| 442 | do_detoast = PG_GETARG_BOOL(5); |
| 443 | |
| 444 | if (!superuser()) |
| 445 | ereport(ERROR, |
| 446 | (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), |
| 447 | errmsg("must be superuser to use raw page functions"))); |
| 448 | |
| 449 | if (!raw_data) |
| 450 | PG_RETURN_NULL(); |
| 451 | |
| 452 | /* |
| 453 | * Convert t_bits string back to the bits8 array as represented in the |
| 454 | * tuple header. |
| 455 | */ |
| 456 | if (t_infomask & HEAP_HASNULL) |
| 457 | { |
| 458 | int bits_str_len; |
| 459 | int bits_len; |
| 460 | |
| 461 | bits_len = BITMAPLEN(t_infomask2 & HEAP_NATTS_MASK) * BITS_PER_BYTE; |
| 462 | if (!t_bits_str) |
| 463 | ereport(ERROR, |
| 464 | (errcode(ERRCODE_DATA_CORRUPTED), |
| 465 | errmsg("t_bits string must not be NULL"))); |
| 466 | |
| 467 | bits_str_len = strlen(t_bits_str); |
| 468 | if (bits_len != bits_str_len) |
| 469 | ereport(ERROR, |
| 470 | (errcode(ERRCODE_DATA_CORRUPTED), |
| 471 | errmsg("unexpected length of t_bits string: %u, expected %u", |
| 472 | bits_str_len, bits_len))); |
| 473 | |
| 474 | /* do the conversion */ |
| 475 | t_bits = text_to_bits(t_bits_str, bits_str_len); |
| 476 | } |
| 477 | else |
| 478 | { |
| 479 | if (t_bits_str) |
nothing calls this directly
no test coverage detected