PostgreSQL Source Code: src/backend/replication/logical/tablesync.c File Reference (original) (raw)

798{

802 Oid tableRow[] = {OIDOID, CHAROID, CHAROID};

803 Oid attrRow[] = {INT2OID, TEXTOID, OIDOID, BOOLOID, BOOLOID};

804 Oid qualRow[] = {TEXTOID};

805 bool isnull;

806 int natt;

810

813

814

816 appendStringInfo(&cmd, "SELECT c.oid, c.relreplident, c.relkind"

817 " FROM pg_catalog.pg_class c"

818 " INNER JOIN pg_catalog.pg_namespace n"

819 " ON (c.relnamespace = n.oid)"

820 " WHERE n.nspname = %s"

821 " AND c.relname = %s",

825 lengthof(tableRow), tableRow);

826

829 (errcode(ERRCODE_CONNECTION_FAILURE),

830 errmsg("could not fetch table info for table \"%s.%s\" from publisher: %s",

832

836 (errcode(ERRCODE_UNDEFINED_OBJECT),

837 errmsg("table \"%s.%s\" not found on publisher",

839

846

849

850

851

852

853

854

855

856

858 {

861 Oid attrsRow[] = {INT2VECTOROID};

862

863

866

867

868

869

870

873 "SELECT DISTINCT"

874 " (CASE WHEN (array_length(gpt.attrs, 1) = c.relnatts)"

875 " THEN NULL ELSE gpt.attrs END)"

876 " FROM pg_publication p,"

877 " LATERAL pg_get_publication_tables(p.pubname) gpt,"

878 " pg_class c"

879 " WHERE gpt.relid = %u AND c.oid = gpt.relid"

880 " AND p.pubname IN ( %s )",

882 pub_names->data);

883

885 lengthof(attrsRow), attrsRow);

886

889 (errcode(ERRCODE_CONNECTION_FAILURE),

890 errmsg("could not fetch column list info for table \"%s.%s\" from publisher: %s",

892

893

894

895

896

897

898

899

900

903 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),

904 errmsg("cannot use different column lists for table \"%s.%s\" in different publications",

906

907

908

909

910

911

912

915 {

917

918 if (!isnull)

919 {

921 int nelems;

923

927

928 for (natt = 0; natt < nelems; natt++)

929 included_cols = bms_add_member(included_cols, elems[natt]);

930 }

931

933 }

935

937 }

938

939

940

941

944 "SELECT a.attnum,"

945 " a.attname,"

946 " a.atttypid,"

947 " a.attnum = ANY(i.indkey)");

948

949

952

954 " FROM pg_catalog.pg_attribute a"

955 " LEFT JOIN pg_catalog.pg_index i"

956 " ON (i.indexrelid = pg_get_replica_identity_index(%u))"

957 " WHERE a.attnum > 0::pg_catalog.int2"

958 " AND NOT a.attisdropped %s"

959 " AND a.attrelid = %u"

960 " ORDER BY a.attnum",

963 "AND a.attgenerated = ''" : ""),

967

970 (errcode(ERRCODE_CONNECTION_FAILURE),

971 errmsg("could not fetch table info for table \"%s.%s\" from publisher: %s",

973

974

978

979

980

981

982

983 natt = 0;

986 {

987 char *rel_colname;

989

992

993

995 {

997 continue;

998 }

999

1002

1003 lrel->attnames[natt] = rel_colname;

1006

1009

1010

1011 if (server_version >= 180000 && !(*gencol_published))

1012 {

1015 }

1016

1017

1019 elog(ERROR, "too many columns in remote table \"%s.%s\"",

1021

1023 }

1025

1026 lrel->natts = natt;

1027

1029

1030

1031

1032

1033

1034

1035

1036

1037

1038

1039

1040

1041

1042

1043

1044

1045

1046

1047

1048

1050 {

1051

1052 Assert(pub_names != NULL);

1053

1054

1057 "SELECT DISTINCT pg_get_expr(gpt.qual, gpt.relid)"

1058 " FROM pg_publication p,"

1059 " LATERAL pg_get_publication_tables(p.pubname) gpt"

1060 " WHERE gpt.relid = %u"

1061 " AND p.pubname IN ( %s )",

1063 pub_names->data);

1064

1066

1069 (errmsg("could not fetch table WHERE clause info for table \"%s.%s\" from publisher: %s",

1071

1072

1073

1074

1075

1076

1077

1078

1081 {

1083

1084 if (!isnull)

1086 else

1087 {

1088

1089 if (*qual)

1090 {

1092 *qual = NIL;

1093 }

1094 break;

1095 }

1096

1098 }

1100

1103 }

1104

1106}

#define DatumGetArrayTypeP(X)

bool bms_is_member(int x, const Bitmapset *a)

Bitmapset * bms_add_member(Bitmapset *a, int x)

#define TextDatumGetCString(d)

TupleTableSlot * MakeSingleTupleTableSlot(TupleDesc tupdesc, const TupleTableSlotOps *tts_ops)

void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)

const TupleTableSlotOps TTSOpsMinimalTuple

#define MaxTupleAttributeNumber

List * lappend(List *list, void *datum)

void * palloc0(Size size)

static int server_version

void GetPublicationsStr(List *publications, StringInfo dest, bool quote_literal)

static bool DatumGetBool(Datum X)

static Oid DatumGetObjectId(Datum X)

static char DatumGetChar(Datum X)

static int16 DatumGetInt16(Datum X)

char * quote_literal_cstr(const char *rawstr)

void destroyStringInfo(StringInfo str)

void resetStringInfo(StringInfo str)

Tuplestorestate * tuplestore

bool tuplestore_gettupleslot(Tuplestorestate *state, bool forward, bool copy, TupleTableSlot *slot)

int64 tuplestore_tuple_count(Tuplestorestate *state)

static Datum slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)

static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)