Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pg15 ybctid #123

Open
wants to merge 4 commits into
base: pg15
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/postgres/src/backend/access/common/heaptuple.c
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,7 @@ heap_form_tuple(TupleDesc tupleDescriptor,
tuple->t_len = len;
ItemPointerSetInvalid(&(tuple->t_self));
tuple->t_tableOid = InvalidOid;
HEAPTUPLE_YBCTID(tuple) = 0;

HeapTupleHeaderSetDatumLength(td, len);
HeapTupleHeaderSetTypeId(td, tupleDescriptor->tdtypeid);
Expand Down Expand Up @@ -1504,6 +1505,7 @@ heap_tuple_from_minimal_tuple(MinimalTuple mtup)
result->t_len = len;
ItemPointerSetInvalid(&(result->t_self));
result->t_tableOid = InvalidOid;
HEAPTUPLE_YBCTID(result) = 0;
result->t_data = (HeapTupleHeader) ((char *) result + HEAPTUPLESIZE);
memcpy((char *) result->t_data + MINIMAL_TUPLE_OFFSET, mtup, mtup->t_len);
memset(result->t_data, 0, offsetof(HeapTupleHeaderData, t_infomask2));
Expand Down
1 change: 1 addition & 0 deletions src/postgres/src/backend/access/common/toast_internals.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ toast_save_datum(Relation rel, Datum value,
if (toastidxs[i]->rd_index->indisready)
index_insert(toastidxs[i], t_values, t_isnull,
&(toasttup->t_self),
0,
toastrel,
toastidxs[i]->rd_index->indisunique ?
UNIQUE_CHECK_YES : UNIQUE_CHECK_NO,
Expand Down
2 changes: 0 additions & 2 deletions src/postgres/src/backend/access/gin/ginpostinglist.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ itemptr_to_uint64(const ItemPointer iptr)
{
uint64 val;

Assert(YbItemPointerYbctid(iptr) == 0);
Assert(ItemPointerIsValid(iptr));
Assert(GinItemPointerGetOffsetNumber(iptr) < (1 << MaxHeapTuplesPerPageBits));

Expand All @@ -102,7 +101,6 @@ itemptr_to_uint64(const ItemPointer iptr)
static inline void
uint64_to_itemptr(uint64 val, ItemPointer iptr)
{
YbItemPointerSetInvalid(iptr);
GinItemPointerSetOffsetNumber(iptr, val & ((1 << MaxHeapTuplesPerPageBits) - 1));
val = val >> MaxHeapTuplesPerPageBits;
GinItemPointerSetBlockNumber(iptr, val);
Expand Down
1 change: 1 addition & 0 deletions src/postgres/src/backend/access/heap/heapam.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ initscan(HeapScanDesc scan, ScanKey key, bool keep_startblock)
scan->rs_inited = false;
scan->rs_ctup.t_data = NULL;
ItemPointerSetInvalid(&scan->rs_ctup.t_self);
HEAPTUPLE_YBCTID(&scan->rs_ctup) = (Datum) 0;
scan->rs_cbuf = InvalidBuffer;
scan->rs_cblock = InvalidBlockNumber;

Expand Down
9 changes: 8 additions & 1 deletion src/postgres/src/backend/access/heap/heapam_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,8 @@ heapam_index_build_range_scan(Relation heapRelation,
void *callback_state,
TableScanDesc scan,
YbBackfillInfo *bfinfo,
YbPgExecOutParam *bfresult)
YbPgExecOutParam *bfresult,
YbIndexBuildCallback ybcallback)
{
HeapScanDesc hscan;
bool is_system_catalog;
Expand Down Expand Up @@ -1732,6 +1733,11 @@ heapam_index_build_range_scan(Relation heapRelation,
callback(indexRelation, &tid, values, isnull, tupleIsAlive,
callback_state);
}
else if (IsYBRelation(indexRelation))
{
ybcallback(indexRelation, heapTuple->t_ybctid, values, isnull,
tupleIsAlive, callback_state);
}
else
{
/* Call the AM's callback routine to process the tuple */
Expand Down Expand Up @@ -2010,6 +2016,7 @@ heapam_index_validate_scan(Relation heapRelation,
values,
isnull,
&rootTuple,
0, /* YB_TODO: right thing? */
heapRelation,
indexInfo->ii_Unique ?
UNIQUE_CHECK_YES : UNIQUE_CHECK_NO,
Expand Down
6 changes: 2 additions & 4 deletions src/postgres/src/backend/access/index/indexam.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ index_insert(Relation indexRelation,
Datum *values,
bool *isnull,
ItemPointer heap_t_ctid,
Datum ybctid,
Relation heapRelation,
IndexUniqueCheck checkUnique,
bool indexUnchanged,
Expand All @@ -217,7 +218,7 @@ index_insert(Relation indexRelation,
if (IsYugaByteEnabled() && IsYBRelation(indexRelation))
{
return indexRelation->rd_indam->yb_aminsert(indexRelation, values, isnull,
heap_t_ctid, heapRelation,
ybctid, heapRelation,
checkUnique, indexInfo,
yb_shared_insert);
}
Expand Down Expand Up @@ -619,7 +620,6 @@ index_getnext_tid(IndexScanDesc scan, ScanDirection direction)
*/
Assert(IsYBRelation(scan->indexRelation) ?
(!ItemPointerIsValid(&scan->xs_heaptid) &&
YbItemPointerYbctid(&scan->xs_heaptid) == 0 &&
(!TupIsNull(scan->yb_agg_slot) ||
scan->xs_hitup != NULL ||
scan->xs_itup != NULL)) :
Expand Down Expand Up @@ -724,7 +724,6 @@ index_getnext_slot(IndexScanDesc scan, ScanDirection direction, TupleTableSlot *
*/
Assert(IsYBRelation(scan->indexRelation) ?
(!ItemPointerIsValid(&scan->xs_heaptid) &&
YbItemPointerYbctid(&scan->xs_heaptid) == 0 &&
(!TupIsNull(scan->yb_agg_slot) ||
scan->xs_hitup != NULL)) :
ItemPointerIsValid(&scan->xs_heaptid));
Expand All @@ -740,7 +739,6 @@ index_getnext_slot(IndexScanDesc scan, ScanDirection direction, TupleTableSlot *
*/
Assert(IsYBRelation(scan->indexRelation) ?
(!ItemPointerIsValid(&scan->xs_heaptid) &&
YbItemPointerYbctid(&scan->xs_heaptid) == 0 &&
(!TupIsNull(scan->yb_agg_slot) ||
scan->xs_hitup != NULL)) :
ItemPointerIsValid(&scan->xs_heaptid));
Expand Down
17 changes: 9 additions & 8 deletions src/postgres/src/backend/access/yb_access/yb_lsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,16 @@ doBindsForIdxWrite(YBCPgStatement stmt,
}

static void
ybcinbuildCallback(Relation index, ItemPointer tid, Datum *values, bool *isnull,
bool tupleIsAlive, void *state)
ybcinbuildCallback(Relation index, Datum ybctid, Datum *values,
bool *isnull, bool tupleIsAlive, void *state)
{
YBCBuildState *buildstate = (YBCBuildState *)state;

if (!buildstate->isprimary)
YBCExecuteInsertIndex(index,
values,
isnull,
tid,
ybctid,
buildstate->backfill_write_time,
doBindsForIdxWrite,
NULL /* indexstate */);
Expand All @@ -167,8 +167,9 @@ ybcinbuild(Relation heap, Relation index, struct IndexInfo *indexInfo)
*/
if (!index->rd_index->indisprimary)
{
heap_tuples = table_index_build_scan(heap, index, indexInfo, true, false,
ybcinbuildCallback, &buildstate, NULL);
heap_tuples = yb_table_index_build_scan(heap, index, indexInfo, true,
ybcinbuildCallback, &buildstate,
NULL);
}
/*
* Return statistics
Expand Down Expand Up @@ -218,7 +219,7 @@ ybcinbuildempty(Relation index)
}

static bool
ybcininsert(Relation index, Datum *values, bool *isnull, ItemPointer tid, Relation heap,
ybcininsert(Relation index, Datum *values, bool *isnull, Datum ybctid, Relation heap,
IndexUniqueCheck checkUnique, struct IndexInfo *indexInfo, bool sharedInsert)
{
if (!index->rd_index->indisprimary)
Expand All @@ -239,7 +240,7 @@ ybcininsert(Relation index, Datum *values, bool *isnull, ItemPointer tid, Relati
index,
values,
isnull,
tid,
ybctid,
NULL /* backfill_write_time */,
doBindsForIdxWrite,
NULL /* indexstate */);
Expand All @@ -250,7 +251,7 @@ ybcininsert(Relation index, Datum *values, bool *isnull, ItemPointer tid, Relati
YBCExecuteInsertIndex(index,
values,
isnull,
tid,
ybctid,
NULL /* backfill_write_time */,
doBindsForIdxWrite,
NULL /* indexstate */);
Expand Down
80 changes: 40 additions & 40 deletions src/postgres/src/backend/access/yb_access/yb_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -3650,7 +3650,7 @@ void ybcIndexCostEstimate(struct PlannerInfo *root, IndexPath *path,
}

static bool
YbFetchRowData(YBCPgStatement ybc_stmt, Relation relation, ItemPointer tid,
YbFetchRowData(YBCPgStatement ybc_stmt, Relation relation, Datum ybctid,
Datum *values, bool *nulls, YBCPgSysColumns *syscols)
{
bool has_data = false;
Expand All @@ -3660,7 +3660,7 @@ YbFetchRowData(YBCPgStatement ybc_stmt, Relation relation, ItemPointer tid,
YBCPgExpr ybctid_expr = YBCNewConstant(ybc_stmt,
BYTEAOID,
InvalidOid,
YbItemPointerYbctid(tid),
ybctid,
false);
HandleYBStatus(YBCPgDmlBindColumn(ybc_stmt, YBTupleIdAttributeNumber, ybctid_expr));

Expand Down Expand Up @@ -3691,45 +3691,45 @@ YbFetchRowData(YBCPgStatement ybc_stmt, Relation relation, ItemPointer tid,
return has_data;
}

bool
YbFetchTableSlot(Relation relation, ItemPointer tid, TupleTableSlot *slot)
{
bool has_data = false;
YBCPgStatement ybc_stmt;

Assert(slot != NULL);
Assert(slot->tts_values != NULL);
Assert(slot->tts_isnull != NULL);

TupleDesc tupdesc = RelationGetDescr(relation);
YBCPgSysColumns syscols;

/* Read data */
HandleYBStatus(YBCPgNewSelect(YBCGetDatabaseOid(relation),
YbGetRelfileNodeId(relation),
NULL /* prepare_params */,
YBCIsRegionLocal(relation),
&ybc_stmt));
has_data = YbFetchRowData(ybc_stmt, relation, tid, slot->tts_values, slot->tts_isnull, &syscols);

/* Write into the given slot */
if (has_data)
{
slot->tts_nvalid = tupdesc->natts;
slot->tts_tableOid = RelationGetRelid(relation);
slot->tts_flags &= ~TTS_FLAG_EMPTY; /* Not empty */
if (syscols.ybctid != NULL)
{
TABLETUPLE_YBCTID(slot) = PointerGetDatum(syscols.ybctid);
}
}

YBCPgDeleteStatement(ybc_stmt);
return has_data;
}
// bool
// YbFetchTableSlot(Relation relation, ItemPointer tid, TupleTableSlot *slot)
// {
// bool has_data = false;
// YBCPgStatement ybc_stmt;

// Assert(slot != NULL);
// Assert(slot->tts_values != NULL);
// Assert(slot->tts_isnull != NULL);

// TupleDesc tupdesc = RelationGetDescr(relation);
// YBCPgSysColumns syscols;

// /* Read data */
// HandleYBStatus(YBCPgNewSelect(YBCGetDatabaseOid(relation),
// YbGetRelfileNodeId(relation),
// NULL /* prepare_params */,
// YBCIsRegionLocal(relation),
// &ybc_stmt));
// has_data = YbFetchRowData(ybc_stmt, relation, tid, slot->tts_values, slot->tts_isnull, &syscols);

// /* Write into the given slot */
// if (has_data)
// {
// slot->tts_nvalid = tupdesc->natts;
// slot->tts_tableOid = RelationGetRelid(relation);
// slot->tts_flags &= ~TTS_FLAG_EMPTY; /* Not empty */
// if (syscols.ybctid != NULL)
// {
// TABLETUPLE_YBCTID(slot) = PointerGetDatum(syscols.ybctid);
// }
// }

// YBCPgDeleteStatement(ybc_stmt);
// return has_data;
// }

bool
YbFetchHeapTuple(Relation relation, ItemPointer tid, HeapTuple* tuple)
YbFetchHeapTuple(Relation relation, Datum ybctid, HeapTuple* tuple)
{
bool has_data = false;
YBCPgStatement ybc_stmt;
Expand All @@ -3745,7 +3745,7 @@ YbFetchHeapTuple(Relation relation, ItemPointer tid, HeapTuple* tuple)
NULL /* prepare_params */,
YBCIsRegionLocal(relation),
&ybc_stmt));
has_data = YbFetchRowData(ybc_stmt, relation, tid, values, nulls, &syscols);
has_data = YbFetchRowData(ybc_stmt, relation, ybctid, values, nulls, &syscols);

/* Write into the given tuple */
if (has_data)
Expand Down
Loading