Skip to content

Commit

Permalink
[MERGE PG15] Initdb fixes till setup_collation()
Browse files Browse the repository at this point in the history
Summary: Initdb fixes till setup_collation()

Test Plan: Jenkins: skip

Reviewers: neil, mihnea

Reviewed By: neil

Subscribers: yql

Differential Revision: https://phorge.dev.yugabyte.com/D25341
  • Loading branch information
arpang authored and nocaway committed Jul 20, 2023
1 parent 963f869 commit b2ca34c
Show file tree
Hide file tree
Showing 30 changed files with 202 additions and 1,441 deletions.
1 change: 0 additions & 1 deletion src/postgres/src/backend/access/common/indextuple.c
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,6 @@ CopyIndexTuple(IndexTuple source)
size = IndexTupleSize(source);
result = (IndexTuple) palloc(size);
memcpy(result, source, size);
INDEXTUPLE_COPY_YBITEM(source, result);
return result;
}

Expand Down
8 changes: 8 additions & 0 deletions src/postgres/src/backend/access/heap/heapam.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@
#include "utils/snapmgr.h"
#include "utils/spccache.h"

/* Yugabyte includes */
#include "pg_yb_utils.h"
#include "executor/ybcModifyTable.h"
#include "access/yb_scan.h"
#include "utils/builtins.h"

static HeapTuple heap_prepare_insert(Relation relation, HeapTuple tup,
TransactionId xid, CommandId cid, int options);
Expand Down Expand Up @@ -4338,6 +4340,12 @@ heap_lock_tuple(Relation relation, HeapTuple tuple,
tuple->t_len = ItemIdGetLength(lp);
tuple->t_tableOid = RelationGetRelid(relation);

/*
* This will only be used for non-YB tuples (e.g. Temp tables) so we just
* need to set the ybctid to 0 (NULL) here.
*/
HEAPTUPLE_YBCTID(tuple) = (Datum) 0;

l3:
result = HeapTupleSatisfiesUpdate(tuple, cid, *buffer);

Expand Down
19 changes: 9 additions & 10 deletions src/postgres/src/backend/access/index/indexam.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ index_insert(Relation indexRelation,
bool yb_shared_insert)
{
RELATION_CHECKS;
CHECK_REL_PROCEDURE(aminsert);
if (IsYugaByteEnabled() && IsYBRelation(indexRelation))
CHECK_REL_PROCEDURE(yb_aminsert);
else
CHECK_REL_PROCEDURE(aminsert);

if (!(indexRelation->rd_indam->ampredlocks))
CheckForSerializableConflictIn(indexRelation,
Expand All @@ -211,20 +214,16 @@ index_insert(Relation indexRelation,
*/
if (IsYugaByteEnabled() && IsYBRelation(indexRelation))
{
CHECK_REL_PROCEDURE(yb_aminsert);
return indexRelation->rd_indam->yb_aminsert(indexRelation, values, isnull,
heap_t_ctid, heapRelation,
checkUnique, indexInfo,
yb_shared_insert);
}
else
{
CHECK_REL_PROCEDURE(aminsert);
return indexRelation->rd_indam->aminsert(indexRelation, values, isnull,
heap_t_ctid, heapRelation,
checkUnique, indexUnchanged,
indexInfo);
}

return indexRelation->rd_indam->aminsert(indexRelation, values, isnull,
heap_t_ctid, heapRelation,
checkUnique, indexUnchanged,
indexInfo);
}

/* ----------------
Expand Down
3 changes: 3 additions & 0 deletions src/postgres/src/backend/access/nbtree/nbtdedup.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#include "miscadmin.h"
#include "utils/rel.h"

/* Yugabyte includes */
#include "utils/builtins.h"

static void _bt_bottomupdel_finish_pending(Page page, BTDedupState state,
TM_IndexDeleteOp *delstate);
static bool _bt_do_singleval(Relation rel, Page page, BTDedupState state,
Expand Down
2 changes: 2 additions & 0 deletions src/postgres/src/backend/access/nbtree/nbtutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include "utils/rel.h"
#include "utils/typcache.h"

/* Yugabyte includes */
#include "utils/builtins.h"

typedef struct BTSortArrayContext
{
Expand Down
15 changes: 8 additions & 7 deletions src/postgres/src/backend/access/yb_access/yb_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -3035,6 +3035,7 @@ YbFetchTableSlot(Relation relation, ItemPointer tid, TupleTableSlot *slot)
{
TABLETUPLE_YBCTID(slot) = PointerGetDatum(syscols.ybctid);
}
/* YB_TODO: Why are we not setting values and nulls. */
}

/* Free up memory and return data */
Expand All @@ -3045,7 +3046,7 @@ YbFetchTableSlot(Relation relation, ItemPointer tid, TupleTableSlot *slot)
}

bool
YbFetchHeapTuple(Relation relation, ItemPointer tid, HeapTuple tuple)
YbFetchHeapTuple(Relation relation, ItemPointer tid, HeapTuple* tuple)
{
bool has_data = false;
YBCPgStatement ybc_stmt;
Expand All @@ -3066,7 +3067,7 @@ YbFetchHeapTuple(Relation relation, ItemPointer tid, HeapTuple tuple)
/* Write into the given tuple */
if (has_data)
{
tuple = heap_form_tuple(tupdesc, values, nulls);
*tuple = heap_form_tuple(tupdesc, values, nulls);
#ifdef YB_TODO
/* YB_TODO(neil@yugabyte)
* - OID is now a regular column.
Expand All @@ -3077,10 +3078,10 @@ YbFetchHeapTuple(Relation relation, ItemPointer tid, HeapTuple tuple)
HeapTupleSetOid(tuple, syscols.oid);
}
#endif
tuple->t_tableOid = RelationGetRelid(relation);
(*tuple)->t_tableOid = RelationGetRelid(relation);
if (syscols.ybctid != NULL)
{
HEAPTUPLE_YBCTID(tuple) = PointerGetDatum(syscols.ybctid);
HEAPTUPLE_YBCTID(*tuple) = PointerGetDatum(syscols.ybctid);
}
}

Expand Down Expand Up @@ -3376,19 +3377,19 @@ ybFetchNext(YBCPgStatement handle,
slot->tts_nvalid = tupdesc->natts;
slot->tts_flags &= ~TTS_FLAG_EMPTY; /* Not empty */
TABLETUPLE_YBCTID(slot) = PointerGetDatum(syscols.ybctid);
#ifdef YB_TODO
/* OID is now a regular column */
if (syscols.oid != InvalidOid)
{
MemoryContext oldcontext = MemoryContextSwitchTo(slot->tts_mcxt);
HeapTuple tuple = heap_form_tuple(tupdesc, values, nulls);
#ifdef YB_TODO
/* OID is now a regular column */
HeapTupleSetOid(tuple, syscols.oid);
#endif
tuple->t_tableOid = relid;
HEAPTUPLE_YBCTID(tuple) = TABLETUPLE_YBCTID(slot);
slot = ExecStoreHeapTuple(tuple, slot, true);
MemoryContextSwitchTo(oldcontext);
}
#endif
}

return slot;
Expand Down
19 changes: 9 additions & 10 deletions src/postgres/src/backend/catalog/indexing.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@ CatalogTupleCheckConstraints(Relation heapRel, HeapTuple tup)
void
CatalogTupleInsert(Relation heapRel, HeapTuple tup)
{
if (IsYugaByteEnabled())
{
return YBCatalogTupleInsert(heapRel, tup, false);
}

CatalogIndexState indstate;

CatalogTupleCheckConstraints(heapRel, tup);
Expand All @@ -348,14 +353,10 @@ CatalogTupleInsert(Relation heapRel, HeapTuple tup)
void
YBCatalogTupleInsert(Relation heapRel, HeapTuple tup, bool yb_shared_insert)
{

if (!IsYugaByteEnabled())
{
return CatalogTupleInsert(heapRel, tup);
}

CatalogIndexState indstate;

CatalogTupleCheckConstraints(heapRel, tup);

/* YB_TODO(neil & sushant@yugabyte)
* Work out a solution for the OID situation in catalog insert.
*/
Expand Down Expand Up @@ -554,8 +555,7 @@ CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
{
if (YbItemPointerYbctid(otid))
{
HeapTuple oldtup = NULL;
YbFetchHeapTuple(heapRel, otid, oldtup);
YbFetchHeapTuple(heapRel, otid, &oldtup);
CatalogIndexDelete(indstate, oldtup);
}
else
Expand Down Expand Up @@ -603,8 +603,7 @@ CatalogTupleUpdateWithInfo(Relation heapRel, ItemPointer otid, HeapTuple tup,
{
if (YbItemPointerYbctid(otid))
{
HeapTuple oldtup = NULL;
YbFetchHeapTuple(heapRel, otid, oldtup);
YbFetchHeapTuple(heapRel, otid, &oldtup);
CatalogIndexDelete(indstate, oldtup);
}
else
Expand Down
52 changes: 28 additions & 24 deletions src/postgres/src/backend/catalog/system_views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@
* in any error message about one of them, so don't do that. Also, you
* cannot write a semicolon immediately followed by an empty line in a
* string literal (including a function body!) or a multiline comment.
*
* Portions Copyright (c) YugabyteDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

CREATE VIEW pg_roles AS
Expand Down Expand Up @@ -648,9 +663,6 @@ GRANT SELECT ON pg_backend_memory_contexts TO pg_read_all_stats;
REVOKE EXECUTE ON FUNCTION pg_get_backend_memory_contexts() FROM PUBLIC;
GRANT EXECUTE ON FUNCTION pg_get_backend_memory_contexts() TO pg_read_all_stats;

CREATE VIEW pg_backend_memory_contexts AS
SELECT * FROM pg_get_backend_memory_contexts();

-- Statistics views

CREATE VIEW pg_stat_all_tables AS
Expand Down Expand Up @@ -866,10 +878,15 @@ CREATE VIEW pg_stat_activity AS
s.backend_xmin,
S.query_id,
S.query,
S.backend_type
S.backend_type,
yb_pg_stat_get_backend_catalog_version(B.beid) AS catalog_version,
yb_pg_stat_get_backend_allocated_mem_bytes(B.beid) AS allocated_mem_bytes,
yb_pg_stat_get_backend_rss_mem_bytes(B.beid) AS rss_mem_bytes
FROM pg_stat_get_activity(NULL) AS S
LEFT JOIN pg_database AS D ON (S.datid = D.oid)
LEFT JOIN pg_authid AS U ON (S.usesysid = U.oid);
LEFT JOIN pg_authid AS U ON (S.usesysid = U.oid)
LEFT JOIN (pg_stat_get_backend_idset() beid CROSS JOIN
pg_stat_get_backend_pid(beid) pid) B ON B.pid = S.pid;

CREATE VIEW pg_stat_replication AS
SELECT
Expand Down Expand Up @@ -1196,6 +1213,8 @@ CREATE VIEW pg_stat_progress_cluster AS
FROM pg_stat_get_progress_info('CLUSTER') AS S
LEFT JOIN pg_database D ON S.datid = D.oid;

-- YB_TODO(Fizaa): Verify if the below schema is correct. This is the latest schema as of PG15.2
-- but it differs from what YB had.
CREATE VIEW pg_stat_progress_create_index AS
SELECT
S.pid AS pid, S.datid AS datid, D.datname AS datname,
Expand Down Expand Up @@ -1260,25 +1279,10 @@ CREATE VIEW pg_stat_progress_copy AS
WHEN 3 THEN 'PIPE'
WHEN 4 THEN 'CALLBACK'
END AS "type",
S.param1 AS bytes_processed,
S.param2 AS bytes_total,
S.param3 AS tuples_processed,
S.param4 AS tuples_excluded
FROM pg_stat_get_progress_info('COPY') AS S
LEFT JOIN pg_database D ON S.datid = D.oid;

CREATE VIEW pg_stat_progress_copy AS
SELECT
S.pid AS pid, S.datid AS datid, D.datname AS datname,
S.relid AS relid,
CASE S.param5 WHEN 1 THEN 'COPY FROM'
WHEN 2 THEN 'COPY TO'
END AS command,
CASE S.param6 WHEN 1 THEN 'FILE'
WHEN 2 THEN 'PROGRAM'
WHEN 3 THEN 'PIPE'
WHEN 4 THEN 'CALLBACK'
END AS "type",
CASE S.param7 WHEN 0 THEN 'IN PROGRESS'
WHEN 1 THEN 'ERROR'
WHEN 2 THEN 'SUCCESS'
END AS yb_status,
S.param1 AS bytes_processed,
S.param2 AS bytes_total,
S.param3 AS tuples_processed,
Expand Down
3 changes: 3 additions & 0 deletions src/postgres/src/backend/catalog/yb_catalog/yb_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ YbDataTypeFromOidMod(int attnum, Oid type_id)
case SelfItemPointerAttributeNumber: /* ctid */
type_id = TIDOID;
break;
#ifdef YB_TODO
/* OID is a regular column PG15 onwards. */
case ObjectIdAttributeNumber: /* oid */
#endif
case TableOidAttributeNumber: /* tableoid */
type_id = OIDOID;
break;
Expand Down
Loading

0 comments on commit b2ca34c

Please sign in to comment.