* Set up execution state for an array subscript operation. */
| 470 | * Set up execution state for an array subscript operation. |
| 471 | */ |
| 472 | static void |
| 473 | array_exec_setup(const SubscriptingRef *sbsref, |
| 474 | SubscriptingRefState *sbsrefstate, |
| 475 | SubscriptExecSteps *methods) |
| 476 | { |
| 477 | bool is_slice = (sbsrefstate->numlower != 0); |
| 478 | ArraySubWorkspace *workspace; |
| 479 | |
| 480 | /* |
| 481 | * Enforce the implementation limit on number of array subscripts. This |
| 482 | * check isn't entirely redundant with checking at parse time; conceivably |
| 483 | * the expression was stored by a backend with a different MAXDIM value. |
| 484 | */ |
| 485 | if (sbsrefstate->numupper > MAXDIM) |
| 486 | ereport(ERROR, |
| 487 | (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), |
| 488 | errmsg("number of array dimensions (%d) exceeds the maximum allowed (%d)", |
| 489 | sbsrefstate->numupper, MAXDIM))); |
| 490 | |
| 491 | /* Should be impossible if parser is sane, but check anyway: */ |
| 492 | if (sbsrefstate->numlower != 0 && |
| 493 | sbsrefstate->numupper != sbsrefstate->numlower) |
| 494 | elog(ERROR, "upper and lower index lists are not same length"); |
| 495 | |
| 496 | /* |
| 497 | * Allocate type-specific workspace. |
| 498 | */ |
| 499 | workspace = (ArraySubWorkspace *) palloc(sizeof(ArraySubWorkspace)); |
| 500 | sbsrefstate->workspace = workspace; |
| 501 | |
| 502 | /* |
| 503 | * Collect datatype details we'll need at execution. |
| 504 | */ |
| 505 | workspace->refelemtype = sbsref->refelemtype; |
| 506 | workspace->refattrlength = get_typlen(sbsref->refcontainertype); |
| 507 | get_typlenbyvalalign(sbsref->refelemtype, |
| 508 | &workspace->refelemlength, |
| 509 | &workspace->refelembyval, |
| 510 | &workspace->refelemalign); |
| 511 | |
| 512 | /* |
| 513 | * Pass back pointers to appropriate step execution functions. |
| 514 | */ |
| 515 | methods->sbs_check_subscripts = array_subscript_check_subscripts; |
| 516 | if (is_slice) |
| 517 | { |
| 518 | methods->sbs_fetch = array_subscript_fetch_slice; |
| 519 | methods->sbs_assign = array_subscript_assign_slice; |
| 520 | methods->sbs_fetch_old = array_subscript_fetch_old_slice; |
| 521 | } |
| 522 | else |
| 523 | { |
| 524 | methods->sbs_fetch = array_subscript_fetch; |
| 525 | methods->sbs_assign = array_subscript_assign; |
| 526 | methods->sbs_fetch_old = array_subscript_fetch_old; |
| 527 | } |
| 528 | } |
| 529 |
nothing calls this directly
no test coverage detected