Skip to content

Commit

Permalink
[MERGE PG15] ysql: add yb_make_greater_string
Browse files Browse the repository at this point in the history
Summary:
When migrating from PG 11.2 to PG 15, we come across commit
49fa99e54ec0ded180b52a4a14e543702d53e8c9 that makes make_greater_string
private:

    Move pattern selectivity code from selfuncs.c to like_support.c.
    ...
    This change localizes the use of pattern_fixed_prefix() and
    make_greater_string() so that they no longer need be exported.
    (We might get pushback from extensions about that, perhaps,
    in which case I'd be inclined to re-export them in a new header
    file like_support.h.)
    ...

ybgin uses make_greater_string for tsvector prefix logic.  Since it is
not trivial to indirectly get the benefit of make_greater_string through
the publicly exposed support functions (they take complex Node
argument), lean towards re-exposing the function through new header
yb_like_support.h and new function yb_make_greater_string.  If, in the
future, upstream postgres decides to expose make_greater_string, these
changes can be scrapped in favor of using make_greater_string again.

Test Plan: Jenkins: compile only, rebase: pg15

Reviewers: neil, amartsinchyk

Reviewed By: amartsinchyk

Subscribers: yql

Differential Revision: https://phabricator.dev.yugabyte.com/D23110
  • Loading branch information
jaki authored and nocaway committed Jul 20, 2023
1 parent b15ae1e commit f675a5f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/postgres/src/backend/access/ybgin/ybginget.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "utils/memutils.h"
#include "utils/rel.h"
#include "utils/selfuncs.h"
#include "utils/yb_like_support.h"

#include "pg_yb_utils.h"
#include "yb/yql/pggate/ybc_pggate.h"
Expand Down Expand Up @@ -261,7 +262,7 @@ get_greaterstr(Datum prefix, Oid datatype, Oid colloid)
Oid opfamily;
Oid oproid;

/* make_greater_string cannot accurately handle non-C collations. */
/* yb_make_greater_string cannot accurately handle non-C collations. */
if (!lc_collate_is_c(colloid))
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
Expand All @@ -287,16 +288,7 @@ get_greaterstr(Datum prefix, Oid datatype, Oid colloid)
elog(ERROR, "no < operator for opfamily %u", opfamily);
fmgr_info(get_opcode(oproid), &ltproc);
prefix_const = text_to_const(prefix, colloid);
#ifdef YB_TODO
/* YB_TODO(jasonk@yugabyte)
* Postgres has stopped calling make_greater_string() in all backend executions. Need to
* investigate if this call is the right thing to do.
*/
return make_greater_string(prefix_const, &ltproc, colloid);
#else
/* This code is only for the compilation to proceed without errors */
return prefix_const;
#endif
return yb_make_greater_string(prefix_const, &ltproc, colloid);
}

static void
Expand Down
9 changes: 9 additions & 0 deletions src/postgres/src/backend/utils/adt/like_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -1770,3 +1770,12 @@ string_to_bytea_const(const char *str, size_t str_len)

return makeConst(BYTEAOID, -1, InvalidOid, -1, conval, false, false);
}

/*
* Externally exposed make_greater_string used by YB.
*/
Const *
yb_make_greater_string(const Const *str_const, FmgrInfo *ltproc, Oid collation)
{
return make_greater_string(str_const, ltproc, collation);
}
37 changes: 37 additions & 0 deletions src/postgres/src/include/utils/yb_like_support.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*--------------------------------------------------------------------------
*
* yb_like_support.h
* External like support functions.
*
* Copyright (c) Yugabyte, 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.
*
* IDENTIFICATION
* src/include/utils/yb_like_support.h
*--------------------------------------------------------------------------
*/

#include "postgres.h"

#include "fmgr.h"
#include "nodes/primnodes.h"
#include "postgres_ext.h"

/*
* Postgres 11 -> 15 changed make_greater_string to static, so reexpose as
* yb_make_greater_string. If, in the future, postgres decides to expose
* make_greater_string via a like_support.h, this can be replaced by that.
*/
Const *yb_make_greater_string(const Const *str_const, FmgrInfo *ltproc,
Oid collation);

0 comments on commit f675a5f

Please sign in to comment.