← Back to Overview

src/bin/pg_dump/common.c

Coverage: 0/0 lines (0.0%)
Total Lines
0
modified
Covered
0
0.0%
Uncovered
0
100.0%
키보드 네비게이션
flagInhAttrs() lines 478-647
Modified Lines Coverage: 0/0 lines (0.0%)
LineHitsSourceCommit
478 - flagInhAttrs(Archive *fout, DumpOptions *dopt, TableInfo *tblinfo, int numTables) -
479 - { -
480 - int i, -
481 - j, -
482 - k; -
483 - -
484 - /* -
485 - * We scan the tables in OID order, since that's how tblinfo[] is sorted. -
486 - * Hence we will typically visit parents before their children --- but -
487 - * that is *not* guaranteed. Thus this loop must be careful that it does -
488 - * not alter table properties in a way that could change decisions made at -
489 - * child tables during other iterations. -
490 - */ -
491 - for (i = 0; i < numTables; i++) -
492 - { -
493 - TableInfo *tbinfo = &(tblinfo[i]); -
494 - int numParents; -
495 - TableInfo **parents; -
496 - -
497 - /* Some kinds never have parents */ -
498 - if (tbinfo->relkind == RELKIND_SEQUENCE || -
499 - tbinfo->relkind == RELKIND_VIEW || -
500 - tbinfo->relkind == RELKIND_MATVIEW || 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
501 - tbinfo->relkind == RELKIND_PROPGRAPH) 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
502 - continue; -
503 - -
504 - /* Don't bother computing anything for non-target tables, either */ -
505 - if (!tbinfo->dobj.dump) -
506 - continue; -
507 - -
508 - numParents = tbinfo->numParents; -
509 - parents = tbinfo->parents; -
510 - -
511 - if (numParents == 0) -
512 - continue; /* nothing to see here, move along */ -
513 - -
514 - /* For each column, search for matching column names in parent(s) */ -
515 - for (j = 0; j < tbinfo->numatts; j++) -
516 - { -
517 - bool foundNotNull; /* Attr was NOT NULL in a parent */ -
518 - bool foundDefault; /* Found a default in a parent */ -
519 - bool foundSameGenerated; /* Found matching GENERATED */ -
520 - bool foundDiffGenerated; /* Found non-matching GENERATED */ -
521 - bool allNotNullsInvalid = true; /* is NOT NULL NOT VALID -
522 - * on all parents? */ -
523 - -
524 - /* no point in examining dropped columns */ -
525 - if (tbinfo->attisdropped[j]) -
526 - continue; -
527 - -
528 - foundNotNull = false; -
529 - foundDefault = false; -
530 - foundSameGenerated = false; -
531 - foundDiffGenerated = false; -
532 - for (k = 0; k < numParents; k++) -
533 - { -
534 - TableInfo *parent = parents[k]; -
535 - int inhAttrInd; -
536 - -
537 - inhAttrInd = strInArray(tbinfo->attnames[j], -
538 - parent->attnames, -
539 - parent->numatts); -
540 - if (inhAttrInd >= 0) -
541 - { -
542 - AttrDefInfo *parentDef = parent->attrdefs[inhAttrInd]; -
543 - -
544 - /* -
545 - * Account for each parent having a not-null constraint. -
546 - * In versions 18 and later, we don't need this (and those -
547 - * didn't have NO INHERIT.) -
548 - */ -
549 - if (fout->remoteVersion < 180000 && -
550 - parent->notnull_constrs[inhAttrInd] != NULL) -
551 - foundNotNull = true; -
552 - -
553 - /* -
554 - * Keep track of whether all the parents that have a -
555 - * not-null constraint on this column have it as NOT -
556 - * VALID; if they all are, arrange to have it printed for -
557 - * this column. If at least one parent has it as valid, -
558 - * there's no need. -
559 - */ -
560 - if (fout->remoteVersion >= 180000 && -
561 - parent->notnull_constrs[inhAttrInd] && -
562 - !parent->notnull_invalid[inhAttrInd]) -
563 - allNotNullsInvalid = false; -
564 - -
565 - foundDefault |= (parentDef != NULL && -
566 - strcmp(parentDef->adef_expr, "NULL") != 0 && -
567 - !parent->attgenerated[inhAttrInd]); -
568 - if (parent->attgenerated[inhAttrInd]) -
569 - { -
570 - /* these pointer nullness checks are just paranoia */ -
571 - if (parentDef != NULL && -
572 - tbinfo->attrdefs[j] != NULL && -
573 - strcmp(parentDef->adef_expr, -
574 - tbinfo->attrdefs[j]->adef_expr) == 0) -
575 - foundSameGenerated = true; -
576 - else -
577 - foundDiffGenerated = true; -
578 - } -
579 - } -
580 - } -
581 - -
582 - /* -
583 - * In versions < 18, for lack of a better system, we arbitrarily -
584 - * decide that a not-null constraint is not locally defined if at -
585 - * least one of the parents has it. -
586 - */ -
587 - if (fout->remoteVersion < 180000 && foundNotNull) -
588 - tbinfo->notnull_islocal[j] = false; -
589 - -
590 - /* -
591 - * For versions >18, we must print the not-null constraint locally -
592 - * for this table even if it isn't really locally defined, but is -
593 - * valid for the child and no parent has it as valid. -
594 - */ -
595 - if (fout->remoteVersion >= 180000 && allNotNullsInvalid) -
596 - tbinfo->notnull_islocal[j] = true; -
597 - -
598 - /* -
599 - * Manufacture a DEFAULT NULL clause if necessary. This breaks -
600 - * the advice given above to avoid changing state that might get -
601 - * inspected in other loop iterations. We prevent trouble by -
602 - * having the foundDefault test above check whether adef_expr is -
603 - * "NULL", so that it will reach the same conclusion before or -
604 - * after this is done. -
605 - */ -
606 - if (foundDefault && tbinfo->attrdefs[j] == NULL) -
607 - { -
608 - AttrDefInfo *attrDef; -
609 - -
610 - attrDef = pg_malloc_object(AttrDefInfo); -
611 - attrDef->dobj.objType = DO_ATTRDEF; -
612 - attrDef->dobj.catId.tableoid = 0; -
613 - attrDef->dobj.catId.oid = 0; -
614 - AssignDumpId(&attrDef->dobj); -
615 - attrDef->dobj.name = pg_strdup(tbinfo->dobj.name); -
616 - attrDef->dobj.namespace = tbinfo->dobj.namespace; -
617 - attrDef->dobj.dump = tbinfo->dobj.dump; -
618 - -
619 - attrDef->adtable = tbinfo; -
620 - attrDef->adnum = j + 1; -
621 - attrDef->adef_expr = pg_strdup("NULL"); -
622 - -
623 - /* Will column be dumped explicitly? */ -
624 - if (shouldPrintColumn(dopt, tbinfo, j)) -
625 - { -
626 - attrDef->separate = false; -
627 - /* No dependency needed: NULL cannot have dependencies */ -
628 - } -
629 - else -
630 - { -
631 - /* column will be suppressed, print default separately */ -
632 - attrDef->separate = true; -
633 - /* ensure it comes out after the table */ -
634 - addObjectDependency(&attrDef->dobj, -
635 - tbinfo->dobj.dumpId); -
636 - } -
637 - -
638 - tbinfo->attrdefs[j] = attrDef; -
639 - } -
640 - -
641 - /* No need to dump generation expression if it's inheritable */ -
642 - if (foundSameGenerated && !foundDiffGenerated && -
643 - !tbinfo->ispartition && !dopt->binary_upgrade) -
644 - tbinfo->attrdefs[j]->dobj.dump = DUMP_COMPONENT_NONE; -
645 - } -
646 - } -
647 - } -