Skip to content

Commit

Permalink
Rebase with yb::master up to commit 9662afb
Browse files Browse the repository at this point in the history
  • Loading branch information
nocaway committed Jul 20, 2023
1 parent 1cc244c commit 57688f4
Show file tree
Hide file tree
Showing 45 changed files with 3,267 additions and 1,133 deletions.
2 changes: 1 addition & 1 deletion src/postgres/contrib/file_fdw/file_fdw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@ file_acquire_sample_rows(Relation onerel, int elevel,
List *options;
CopyFromState cstate;
ErrorContextCallback errcallback;
MemoryContext oldcontext = GetCurrentMemoryContext;
MemoryContext oldcontext = GetCurrentMemoryContext();
MemoryContext tupcontext;

Assert(onerel);
Expand Down
54 changes: 39 additions & 15 deletions src/postgres/src/backend/access/yb_access/yb_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ ybcBindTupleExprCondIn(YbScanDesc ybScan,
}

YBCPgExpr lhs =
YBCNewTupleExpr(ybScan->handle, &type_attrs, n_attnum_values,
YBCNewTupleExpr(ybScan->handle, &type_attrs, n_attnum_values,
ybc_elems_exprs);

TupleDesc tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
Expand All @@ -301,7 +301,7 @@ ybcBindTupleExprCondIn(YbScanDesc ybScan,
YBEncodingCollation(ybScan->handle, attnum[j],
ybc_get_attcollation(bind_desc, attnum[j]));
ybc_elems_exprs[j] =
YBCNewConstant(ybScan->handle, atttypid, attcollation,
YBCNewConstant(ybScan->handle, atttypid, attcollation,
datum_values[j], is_null[j]);
}

Expand Down Expand Up @@ -746,7 +746,7 @@ YbIsEmptyResultCondition(int nkeys, ScanKey keys[])
for (int i = 0; i < nkeys; i++)
{
ScanKey key = keys[i];

if (!((key->sk_flags & SK_ROW_MEMBER) && YbIsRowHeader(keys[i - 1])) ||
key->sk_strategy == BTEqualStrategyNumber)
{
Expand Down Expand Up @@ -1112,7 +1112,7 @@ YbBindRowComparisonKeys(YbScanDesc ybScan, YbScanPlan scan_plan,
* first column then we have to adjust the bounds on this
* column.
*/
if(!is_column_specified ||
if(!is_column_specified ||
(asc != is_direction_asc && !is_point_scan))
{
col_values[j] = NULL;
Expand Down Expand Up @@ -1205,7 +1205,7 @@ YbBindSearchArray(YbScanDesc ybScan, YbScanPlan scan_plan,
colids = palloc(sizeof(Oid) * subkey_count);
arrayval =
DatumGetArrayTypeP((ybScan->keys[i+1])->sk_argument);

for(size_t j = 0; j < subkey_count; j++)
{
attnos[j] = ybScan->keys[i + j + 1]->sk_attno;
Expand All @@ -1222,7 +1222,7 @@ YbBindSearchArray(YbScanDesc ybScan, YbScanPlan scan_plan,
/* We could cache this data, but not clear it's worth it */
get_typlenbyvalalign(ARR_ELEMTYPE(arrayval), &elmlen,
&elmbyval, &elmalign);

deconstruct_array(arrayval,
ARR_ELEMTYPE(arrayval),
elmlen, elmbyval, elmalign,
Expand All @@ -1232,7 +1232,7 @@ YbBindSearchArray(YbScanDesc ybScan, YbScanPlan scan_plan,
/*
* Compress out any null elements. We can ignore them since we assume
* all btree operators are strict.
* Also remove elements that are too large or too small.
* Also remove elements that are too large or too small.
* eg. WHERE element = INT_MAX + k, where k is positive and element
* is of integer type.
*/
Expand All @@ -1252,8 +1252,8 @@ YbBindSearchArray(YbScanDesc ybScan, YbScanPlan scan_plan,
continue;

/* Skip any rows that have NULLs in them. */
/*
* TODO: record_eq considers NULL record elements to
/*
* TODO: record_eq considers NULL record elements to
* be equal. However, the only way we receive IN filters
* with tuples is through
* compound batched nested loop joins where NULL
Expand Down Expand Up @@ -1667,7 +1667,7 @@ YbBindScanKeys(YbScanDesc ybScan, YbScanPlan scan_plan)
else if (YbIsSearchArray(key))
{
bool bail_out = false;
bool is_bound =
bool is_bound =
YbBindSearchArray(ybScan, scan_plan,
i, is_column_bound,
&bail_out);
Expand Down Expand Up @@ -2358,19 +2358,43 @@ ybc_keys_match(HeapTuple tup, YbScanDesc ybScan, bool *recheck)
return true;
}

static bool is_index_functional(Relation index)
{
if (!index->rd_indexprs)
return false;

ListCell *indexpr_item;

foreach(indexpr_item, index->rd_indexprs)
{
Expr *indexvar = (Expr *) lfirst(indexpr_item);
if (IsA(indexvar, FuncExpr))
{
return true;
}

}
return false;
}

HeapTuple ybc_getnext_heaptuple(YbScanDesc ybScan, bool is_forward_scan, bool *recheck)
{
HeapTuple tup = NULL;

if (ybScan->quit_scan)
return NULL;

/* In case of yb_hash_code pushdown tuple must be rechecked */
/* In case of yb_hash_code pushdown tuple must be rechecked. */
bool tuple_recheck_required = (ybScan->nhash_keys > 0);

/* If the index is on a function, we need to recheck. */
if (ybScan->index)
tuple_recheck_required |= is_index_functional(ybScan->index);

/*
* YB Scan may not be able to push down the scan key condition so we may
* need additional filtering here.
*/
* YB Scan may not be able to push down the scan key condition so we may
* need additional filtering here.
*/
while (HeapTupleIsValid(tup = ybcFetchNextHeapTuple(ybScan, is_forward_scan)))
{
if (tuple_recheck_required)
Expand All @@ -2397,7 +2421,7 @@ IndexTuple ybc_getnext_indextuple(YbScanDesc ybScan, bool is_forward_scan, bool
if (ybScan->quit_scan)
return NULL;

/*
/*
* If we have a yb_hash_code pushdown or not all conditions were
* bound tuple must be rechecked.
*/
Expand Down
Loading

0 comments on commit 57688f4

Please sign in to comment.