yjhjstz commented on code in PR #1010:
URL: https://github.com/apache/cloudberry/pull/1010#discussion_r2016779461
##########
src/backend/access/aocs/aocsam.c:
##########
@@ -675,82 +675,140 @@ aocs_endscan(AOCSScanDesc scan)
pfree(scan);
}
-/*
- * Upgrades a Datum value from a previous version of the AOCS page format. The
- * DatumStreamRead that is passed must correspond to the column being upgraded.
- */
-static void upgrade_datum_impl(DatumStreamRead *ds, int attno, Datum values[],
- bool isnull[], int
formatversion)
+
+static pg_attribute_hot_inline bool
+aocs_getnext_noqual(AOCSScanDesc scan, ScanDirection direction, TupleTableSlot
*slot)
{
- bool convert_numeric = false;
+ Datum *d = slot->tts_values;
+ bool *null = slot->tts_isnull;
+ AOTupleId aoTupleId;
+ int64 rowNum = INT64CONST(-1);
+ int err = 0;
+ bool isSnapshotAny = (scan->rs_base.rs_snapshot ==
SnapshotAny);
+ AttrNumber natts;
- if (PG82NumericConversionNeeded(formatversion))
+ Assert(ScanDirectionIsForward(direction));
+
+ if (scan->columnScanInfo.relationTupleDesc == NULL)
{
- /*
- * On the first call for this DatumStream, figure out if this
column is
- * a numeric, or a domain over numerics.
- *
- * TODO: consolidate this code with upgrade_tuple() in
appendonlyam.c.
- */
- if (!OidIsValid(ds->baseTypeOid))
+ scan->columnScanInfo.relationTupleDesc =
slot->tts_tupleDescriptor;
+ /* Pin it! ... and of course release it upon destruction /
rescan */
+ PinTupleDesc(scan->columnScanInfo.relationTupleDesc);
+ initscan_with_colinfo(scan);
+ }
+
+ natts = slot->tts_tupleDescriptor->natts;
+ Assert(natts <= scan->columnScanInfo.relationTupleDesc->natts);
+
+ while (1)
+ {
+ AOCSFileSegInfo *curseginfo;
+ bool visible_pass;
+
+ReadNext:
+ /* If necessary, open next seg */
+ if (scan->cur_seg < 0 || err < 0)
{
- ds->baseTypeOid = getBaseType(ds->typeInfo.typid);
+ err = open_next_scan_seg(scan);
+ if (err < 0)
+ {
+ /* No more seg, we are at the end */
+ ExecClearTuple(slot);
+ scan->cur_seg = -1;
+ return false;
+ }
+ scan->segrowsprocessed = 0;
}
- /* If this Datum is a numeric, we need to convert it. */
- convert_numeric = (ds->baseTypeOid == NUMERICOID) &&
!isnull[attno];
- }
+ Assert(scan->cur_seg >= 0);
+ curseginfo = scan->seginfo[scan->cur_seg];
- if (convert_numeric)
- {
- /*
- * Before PostgreSQL 8.3, the n_weight and n_sign_dscale fields
were the
- * other way 'round. Swap them.
- */
- Datum datum;
- char *numericdata;
- char *upgradedata;
- size_t datalen;
- uint16 tmp;
+ /* Read from cur_seg */
+ visible_pass = true;
+ for (AttrNumber i = 0; i < scan->columnScanInfo.num_proj_atts;
i++)
+ {
+ AttrNumber attno =
scan->columnScanInfo.proj_atts[i];
- /*
- * We need to make a copy of this data so that any other tuples
pointing
- * to it won't be affected. Store it in the upgrade space for
this
- * DatumStream.
- */
- datum = values[attno];
- datalen = VARSIZE_ANY(DatumGetPointer(datum));
+ err =
datumstreamread_advance(scan->columnScanInfo.ds[attno]);
+ Assert(err >= 0);
+ if (err == 0)
+ {
+ err =
datumstreamread_block(scan->columnScanInfo.ds[attno], scan->blockDirectory,
attno);
+ if (err < 0)
+ {
+ /*
+ * Ha, cannot read next block, we need
to go to next seg
+ */
+ close_cur_scan_seg(scan);
+ goto ReadNext;
+ }
- upgradedata = datumstreamread_get_upgrade_space(ds, datalen);
- memcpy(upgradedata, DatumGetPointer(datum), datalen);
+ AOCSScanDesc_UpdateTotalBytesRead(scan, attno);
- /* Swap the fields. */
- numericdata = VARDATA_ANY(upgradedata);
+ err =
datumstreamread_advance(scan->columnScanInfo.ds[attno]);
+ Assert(err > 0);
+ }
+ if (!visible_pass)
+ continue; /* not break, need advance for other
cols */
- memcpy(&tmp, &numericdata[0], 2);
- memcpy(&numericdata[0], &numericdata[2], 2);
- memcpy(&numericdata[2], &tmp, 2);
+ /*
+ * Get the column's datum right here since the data
structures
+ * should still be hot in CPU data cache memory.
+ */
+ datumstreamread_get(scan->columnScanInfo.ds[attno],
&d[attno], &null[attno]);
- /* Re-point the Datum to the upgraded numeric. */
- values[attno] = PointerGetDatum(upgradedata);
- }
-}
+ if (i == 0)
+ {
+ if (rowNum == INT64CONST(-1) &&
+
scan->columnScanInfo.ds[attno]->blockFirstRowNum != INT64CONST(-1))
+ {
+
Assert(scan->columnScanInfo.ds[attno]->blockFirstRowNum > 0);
+ rowNum =
scan->columnScanInfo.ds[attno]->blockFirstRowNum +
+
datumstreamread_nth(scan->columnScanInfo.ds[attno]);
+ }
+ scan->segrowsprocessed++;
+ if (rowNum == INT64CONST(-1))
+ {
+ AOTupleIdInit(&aoTupleId,
curseginfo->segno, scan->segrowsprocessed);
+ }
+ else
+ {
+ AOTupleIdInit(&aoTupleId,
curseginfo->segno, rowNum);
+ }
-static void upgrade_datum_scan(AOCSScanDesc scan, int attno, Datum values[],
- bool isnull[], int
formatversion)
-{
- upgrade_datum_impl(scan->columnScanInfo.ds[attno], attno, values,
isnull, formatversion);
-}
+ if (!isSnapshotAny &&
!AppendOnlyVisimap_IsVisible(&scan->visibilityMap, &aoTupleId))
+ {
+ /*
+ * The tuple is invisible.
+ * In `analyze`, we can simply return
false
+ */
+ if ((scan->rs_base.rs_flags &
SO_TYPE_ANALYZE) != 0)
+ return false;
-static void upgrade_datum_fetch(AOCSFetchDesc fetch, int attno, Datum values[],
- bool isnull[],
int formatversion)
-{
- upgrade_datum_impl(fetch->datumStreamFetchDesc[attno]->datumStream,
attno,
- values, isnull, formatversion);
+ rowNum = INT64CONST(-1);
+ visible_pass = false;
+ continue; /* not break, need advance
for other cols */
+ }
+ }
+ }
+ if (!visible_pass)
+ {
+ rowNum = INT64CONST(-1);
+ goto ReadNext;
+ }
+ scan->cdb_fake_ctid = *((ItemPointer) &aoTupleId);
+
+ slot->tts_nvalid = natts;
+ slot->tts_tid = scan->cdb_fake_ctid;
+ return true;
+ }
+
+ Assert(!"Never here");
+ return false;
}
-bool
-aocs_getnext(AOCSScanDesc scan, ScanDirection direction, TupleTableSlot *slot)
+static bool
+aocs_getnext_withqual(AOCSScanDesc scan, ScanDirection direction,
TupleTableSlot *slot)
{
if (scan->aos_pushdown_qual && scan->aos_scaned_rows <
scan->aos_sample_rows)
{
Review Comment:
still aocs_getnext()
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]