Skip to content

Commit

Permalink
[#25631] YSQL: add "yb" to all YB types
Browse files Browse the repository at this point in the history
Summary:
Type names that YB introduced in postgres code should have "yb" (case
insensitive) in it, most often as a prefix.  Fix any names that don't
have it.  Find such types by comparing with upstream PG.  See the test
plan for example.

As part of this, remove some types that aren't used:

- Opts_t (remove just the type name)
- PreparedParamsData (removed from PG 11.2 to PG 15.2 by
  2f48ede080f42b97b594fb14102c82ca1001b80c, but YB's merge appears to
  not have removed it)
- pull_varattnos_walker_ptr
- yb_catclist_iterator (remove just the type name)

Note:

- struct hdr_iter is defined in a thirdparty library, so that can't be
  changed to have a "yb" prefix.  Instead, change the typedef to have
  "yb" prefix.
- PgStat_MsgHdr* is ifdef'd out because upstream PG removed that related
  code from PG 11.2 to PG 15.2.  Still do the renames anyway even though
  this code is not used.
- Sort typedefs.list.
- It's not possible to add lint rules because knowledge of which types
  are YB-introduced depends on having a copy of the postgres code.  The
  test plan has this in ~/code/postgres, but that is not something that
  can be guaranteed for all users.  A best effort could be to make sure
  all types defined in YB files have "yb" prefix.  That can be a
  followup.

This is part of a series of commits to run pgindent.  The previous
commit is d20a6b3.
Jira: DB-14881

Test Plan:
On Almalinux 8, Zsh (extended glob), upstream postgres REL_15_2 checked
out in ~/code/postgres, ctags version "Exuberant Ctags 5.8",

    [ -z "$(diff <(cd src/postgres; git ls-files ^third-party-extensions ../yb/yql/pggate/***/ybc_*.h | ctags -L - --languages=c,c++ --c-kinds=gstu --c++-kinds=gstu -f /dev/stdout | awk '{print$1}' | uniq) <(cd ~/code/postgres; git ls-files | ctags -L - --languages=c,c++ --c-kinds=gstu --c++-kinds=gstu -f /dev/stdout | awk '{print$1}' | uniq) | grep '>')" ]
    [ -z "$(diff <(cd src/postgres; git ls-files ^third-party-extensions ../yb/yql/pggate/***/ybc_*.h | ctags -L - --languages=c,c++ --c-kinds=gstu --c++-kinds=gstu -f /dev/stdout | awk '{print$1}' | uniq) <(cd ~/code/postgres; git ls-files | ctags -L - --languages=c,c++ --c-kinds=gstu --c++-kinds=gstu -f /dev/stdout | awk '{print$1}' | uniq) | grep '<' | grep -Ev 'Yb|YB|yb')" ]

Close: #25631

Reviewers: kramanathan

Reviewed By: kramanathan

Subscribers: kramanathan, ybase, yql, ycdcxcluster

Differential Revision: https://phorge.dev.yugabyte.com/D41178
  • Loading branch information
jaki committed Jan 15, 2025
1 parent d518436 commit 6a56ce7
Show file tree
Hide file tree
Showing 81 changed files with 547 additions and 557 deletions.
38 changes: 19 additions & 19 deletions src/postgres/contrib/pg_stat_statements/pg_stat_statements.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ typedef struct Counters
* hdr_histogram
* defined in third party hdr_histogram.h
*/
typedef struct hdr_iter hdr_iter;
typedef struct hdr_iter yb_hdr_iter;

/*
* Global statistics for pg_stat_statements
Expand Down Expand Up @@ -277,7 +277,7 @@ typedef struct
int temp_yb_hdr_count_bytes;
bool hdr_config_match;

} pgssReaderContext;
} pgssYbReaderContext;

/*
* Global shared state
Expand Down Expand Up @@ -450,14 +450,14 @@ static Datum yb_add_histogram_jsonb(JsonbParseState *state,
hdr_histogram *h, size_t yb_slow_executions);
static void yb_hdr_reset(hdr_histogram *h);
static int read_entry_original(int header, FILE *file, FILE *qfile,
pgssReaderContext *context);
pgssYbReaderContext *context);
static int read_entry_hdr(int header, FILE *file, FILE *qfile,
pgssReaderContext *context);
pgssYbReaderContext *context);
static int extended_header_reader(int header, FILE *file,
pgssReaderContext *context);
pgssYbReaderContext *context);
static int query_buffer_helper(FILE *file, FILE *qfile, int qlen,
Size *query_offset, int encoding, Counters *counters,
pgssReaderContext *context);
pgssYbReaderContext *context);
static void enforce_bucket_factor(int * value);
static bool yb_track_nested_queries(void);
static int YbGetPgssNormalizedQueryText(Size query_offset, int actual_query_len, char *normalized_query);
Expand Down Expand Up @@ -663,7 +663,7 @@ resetYsqlStatementStats()

static void
yb_add_hist_json(void *cb_arg, hdr_histogram *h, size_t yb_slow_executions) {
hdr_iter iter;
yb_hdr_iter iter;
StringInfoData buf;
initStringInfo(&buf);

Expand Down Expand Up @@ -774,7 +774,7 @@ getYsqlStatementStats(void *cb_arg)
*/
static int query_buffer_helper(FILE *file, FILE *qfile, int qlen,
Size *query_offset, int encoding, Counters *counters,
pgssReaderContext *context)
pgssYbReaderContext *context)
{
/* Encoding is the only field we can easily sanity-check */
if (!PG_VALID_BE_ENCODING(encoding))
Expand Down Expand Up @@ -810,7 +810,7 @@ static int query_buffer_helper(FILE *file, FILE *qfile, int qlen,
* generated by pre-histogram code.
*/
static int read_entry_original(int header, FILE *file, FILE *qfile,
pgssReaderContext *context)
pgssYbReaderContext *context)
{
typedef struct pgssEntry_original
{
Expand Down Expand Up @@ -862,7 +862,7 @@ static int read_entry_original(int header, FILE *file, FILE *qfile,
* config variables have changed between restarts.
*/
static int read_entry_hdr(int header, FILE *file, FILE *qfile,
pgssReaderContext *context)
pgssYbReaderContext *context)
{
Assert(header == 0x20230330);

Expand Down Expand Up @@ -917,7 +917,7 @@ static int read_entry_hdr(int header, FILE *file, FILE *qfile,
* variables to parse following the standard file header.
*/
static int extended_header_reader(int header, FILE *file,
pgssReaderContext *context)
pgssYbReaderContext *context)
{
if (header != 0x20230330)
return -1;
Expand All @@ -937,12 +937,12 @@ static int extended_header_reader(int header, FILE *file,
return 0;
}

typedef struct pgssReader
typedef struct pgssYbReader
{
uint32 header;
int (*extended_header_reader)(int, FILE*, pgssReaderContext *context);
int (*entry_reader)(int, FILE*, FILE*, pgssReaderContext *context);
} pgssReader;
int (*extended_header_reader)(int, FILE*, pgssYbReaderContext *context);
int (*entry_reader)(int, FILE*, FILE*, pgssYbReaderContext *context);
} pgssYbReader;

/*
* Array of pgssEntry deserialization functions, organized by header member.
Expand All @@ -953,7 +953,7 @@ typedef struct pgssReader
* offsets would be lost.
*/
static const int pgssReaderEndMarker = -1;
pgssReader pgssReaderList[] =
pgssYbReader pgssReaderList[] =
{
{0x20171004, NULL, read_entry_original},
{0x20230330, extended_header_reader, read_entry_hdr},
Expand Down Expand Up @@ -1093,7 +1093,7 @@ pgss_shmem_startup(void)
if (pgver != PGSS_PG_MAJOR_VERSION)
goto data_error;

pgssReader *version_reader = NULL;
pgssYbReader *version_reader = NULL;
int i = 0;
while (pgssReaderList[i].header != pgssReaderEndMarker)
{
Expand All @@ -1108,7 +1108,7 @@ pgss_shmem_startup(void)
if (version_reader == NULL)
goto read_error;

pgssReaderContext context;
pgssYbReaderContext context;
context.num = num;
context.buffer_size = &buffer_size;
context.buffer = &buffer;
Expand Down Expand Up @@ -3532,7 +3532,7 @@ static Datum
yb_add_histogram_jsonb(JsonbParseState *state, hdr_histogram *h,
size_t yb_slow_executions)
{
hdr_iter iter;
yb_hdr_iter iter;

StringInfoData buf;
initStringInfo(&buf);
Expand Down
8 changes: 4 additions & 4 deletions src/postgres/src/backend/access/common/reloptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ static relopt_int intRelOpts[] =
{{NULL}}
};

static relopt_oid oidRelOpts[] =
static yb_relopt_oid oidRelOpts[] =
{
{
{
Expand Down Expand Up @@ -893,7 +893,7 @@ allocate_reloption(bits32 kinds, int type, const char *name, const char *desc,
size = sizeof(relopt_int);
break;
case RELOPT_TYPE_OID:
size = sizeof(relopt_oid);
size = sizeof(yb_relopt_oid);
break;
case RELOPT_TYPE_REAL:
size = sizeof(relopt_real);
Expand Down Expand Up @@ -1787,7 +1787,7 @@ parse_one_reloption(relopt_value *option, char *text_str, int text_len,
break;
case RELOPT_TYPE_OID:
{
relopt_oid *optoid = (relopt_oid *) option->gen;
yb_relopt_oid *optoid = (yb_relopt_oid *) option->gen;

parsed = parse_oid(value, &option->values.oid_val, NULL);
if (validate && !parsed)
Expand Down Expand Up @@ -1963,7 +1963,7 @@ fillRelOptions(void *rdopts, Size basesize,
case RELOPT_TYPE_OID:
*(Oid *) itempos = options[i].isset ?
options[i].values.oid_val :
((relopt_oid *) options[i].gen)->default_val;
((yb_relopt_oid *) options[i].gen)->default_val;
break;
case RELOPT_TYPE_REAL:
*(double *) itempos = options[i].isset ?
Expand Down
62 changes: 31 additions & 31 deletions src/postgres/src/backend/access/yb_access/yb_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -2896,7 +2896,7 @@ YbAppendPrimaryColumnRefs(YbcPgStatement dml, List *colrefs)
}

static void
YbApplyPushdownImpl(YbcPgStatement dml, const PushdownExprs *pushdown,
YbApplyPushdownImpl(YbcPgStatement dml, const YbPushdownExprs *pushdown,
bool is_for_secondary_index)
{
if (!pushdown)
Expand All @@ -2914,13 +2914,13 @@ YbApplyPushdownImpl(YbcPgStatement dml, const PushdownExprs *pushdown,
}

void
YbApplyPrimaryPushdown(YbcPgStatement dml, const PushdownExprs *pushdown)
YbApplyPrimaryPushdown(YbcPgStatement dml, const YbPushdownExprs *pushdown)
{
YbApplyPushdownImpl(dml, pushdown, false /* is_for_secondary_index */);
}

void
YbApplySecondaryIndexPushdown(YbcPgStatement dml, const PushdownExprs *pushdown)
YbApplySecondaryIndexPushdown(YbcPgStatement dml, const YbPushdownExprs *pushdown)
{
YbApplyPushdownImpl(dml, pushdown, true /* is_for_secondary_index */);
}
Expand Down Expand Up @@ -2955,8 +2955,8 @@ ybcBeginScan(Relation relation,
int nkeys,
ScanKey keys,
Scan *pg_scan_plan,
PushdownExprs *rel_pushdown,
PushdownExprs *idx_pushdown,
YbPushdownExprs *rel_pushdown,
YbPushdownExprs *idx_pushdown,
List *aggrefs,
int distinct_prefixlen,
YbcPgExecParameters *exec_params,
Expand Down Expand Up @@ -4243,11 +4243,11 @@ yb_init_partition_key_data(void *data)
ppk->key_data_capacity = YB_PARTITION_KEY_DATA_CAPACITY;
}

typedef int keylen_t;
typedef int yb_keylen_t;
#define KEY_LEN(ppk, key_offset) \
(ppk)->key_data + (key_offset)
#define KEY_DATA(ppk, key_offset) \
(ppk)->key_data + (key_offset) + sizeof(keylen_t)
(ppk)->key_data + (key_offset) + sizeof(yb_keylen_t)

/*
* yb_add_key_unsynchronized
Expand All @@ -4259,15 +4259,15 @@ typedef int keylen_t;
*/
static bool
yb_add_key_unsynchronized(YBParallelPartitionKeys ppk,
const char *key, keylen_t key_len)
const char *key, yb_keylen_t key_len)
{
/* Only the first key is allowed to be empty */
Assert(key_len > 0 || ppk->key_count == 0);
/* Special case: initially empty buffer */
if (ppk->key_count == 0)
{
Assert(sizeof(key_len) + key_len <= ppk->key_data_capacity);
memcpy(KEY_LEN(ppk, 0), &key_len, sizeof(keylen_t));
memcpy(KEY_LEN(ppk, 0), &key_len, sizeof(yb_keylen_t));
/* Update counters, etc */
if (key_len > 0)
{
Expand All @@ -4285,14 +4285,14 @@ yb_add_key_unsynchronized(YBParallelPartitionKeys ppk,
* Wrapped around buffer, the available space lays between the end of
* the high key and the beginning of the low key.
*/
keylen_t high_key_len;
memcpy(&high_key_len, KEY_LEN(ppk, ppk->high_offset), sizeof(keylen_t));
yb_keylen_t high_key_len;
memcpy(&high_key_len, KEY_LEN(ppk, ppk->high_offset), sizeof(yb_keylen_t));
int free_offset = ppk->high_offset + sizeof(int) + high_key_len;
/* Check the room in the buffer */
Assert(free_offset <= ppk->low_offset);
if (ppk->low_offset - free_offset < sizeof(keylen_t) + key_len)
if (ppk->low_offset - free_offset < sizeof(yb_keylen_t) + key_len)
return false;
memcpy(KEY_LEN(ppk, free_offset), &key_len, sizeof(keylen_t));
memcpy(KEY_LEN(ppk, free_offset), &key_len, sizeof(yb_keylen_t));
memcpy(KEY_DATA(ppk, free_offset), key, key_len);
/* Update counters, etc */
++ppk->key_count;
Expand All @@ -4310,7 +4310,7 @@ yb_add_key_unsynchronized(YBParallelPartitionKeys ppk,
/* Check for the trailing space capacity */
if (ppk->key_data_capacity - free_offset >= sizeof(key_len) + key_len)
{
memcpy(KEY_LEN(ppk, free_offset), &key_len, sizeof(keylen_t));
memcpy(KEY_LEN(ppk, free_offset), &key_len, sizeof(yb_keylen_t));
memcpy(KEY_DATA(ppk, free_offset), key, key_len);
/* Update counters, etc */
++ppk->key_count;
Expand All @@ -4325,7 +4325,7 @@ yb_add_key_unsynchronized(YBParallelPartitionKeys ppk,
*/
else if (ppk->low_offset >= sizeof(key_len) + key_len)
{
memcpy(KEY_LEN(ppk, 0), &key_len, sizeof(keylen_t));
memcpy(KEY_LEN(ppk, 0), &key_len, sizeof(yb_keylen_t));
memcpy(KEY_DATA(ppk, 0), key, key_len);
/* Update counters, etc */
++ppk->key_count;
Expand All @@ -4350,11 +4350,11 @@ static void
yb_remove_key_unsynchronized(YBParallelPartitionKeys ppk)
{
Assert(ppk->key_count > 0);
keylen_t key_len;
yb_keylen_t key_len;
--ppk->key_count;
memcpy(&key_len, KEY_LEN(ppk, ppk->low_offset), sizeof(keylen_t));
memcpy(&key_len, KEY_LEN(ppk, ppk->low_offset), sizeof(yb_keylen_t));
/* Find offset of the next element */
int next = ppk->low_offset + sizeof(keylen_t) + key_len;
int next = ppk->low_offset + sizeof(yb_keylen_t) + key_len;
if (next == ppk->key_data_size)
{
/*
Expand All @@ -4377,8 +4377,8 @@ yb_remove_key_unsynchronized(YBParallelPartitionKeys ppk)
}
else
{
memcpy(&key_len, KEY_LEN(ppk, ppk->high_offset), sizeof(keylen_t));
ppk->key_data_size = ppk->high_offset + sizeof(keylen_t) + key_len;
memcpy(&key_len, KEY_LEN(ppk, ppk->high_offset), sizeof(yb_keylen_t));
ppk->key_data_size = ppk->high_offset + sizeof(yb_keylen_t) + key_len;
}
}
ppk->low_offset = next;
Expand All @@ -4397,16 +4397,16 @@ yb_remove_key_unsynchronized(YBParallelPartitionKeys ppk)
* to fetch more and change the fetch state to WORKING. Hence the separate
* field, a counter, to be able to report inefficient fetch.
*/
typedef struct FetchKeysParam
typedef struct YbFetchKeysParam
{
int discarded;
YBParallelPartitionKeys ppk;
} FetchKeysParam;
} YbFetchKeysParam;

static void
ppk_buffer_fetch_callback(void *param, const char *key, size_t key_size)
{
FetchKeysParam *fkp = (FetchKeysParam *) param;
YbFetchKeysParam *fkp = (YbFetchKeysParam *) param;
YBParallelPartitionKeys ppk = fkp->ppk;
/* Once discarded, discard all the keys, just count them */
if (fkp->discarded)
Expand Down Expand Up @@ -4473,14 +4473,14 @@ yb_fetch_partition_keys(YBParallelPartitionKeys ppk)
const char *latest_key;
size_t latest_key_size;
uint64_t max_num_ranges;
FetchKeysParam fkp = {0, ppk};
YbFetchKeysParam fkp = {0, ppk};

/* Estimate fetch parameter values */
SpinLockAcquire(&ppk->mutex);
/* Until fetch is done at least one key must remain in the buffer */
Assert(ppk->key_count > 0);
keylen_t key_len;
memcpy(&key_len, KEY_LEN(ppk, ppk->high_offset), sizeof(keylen_t));
yb_keylen_t key_len;
memcpy(&key_len, KEY_LEN(ppk, ppk->high_offset), sizeof(yb_keylen_t));
latest_key_size = key_len;
/* Empty key indicates the end of the keys, fetch shouldn't be possible. */
Assert(latest_key_size);
Expand All @@ -4496,7 +4496,7 @@ yb_fetch_partition_keys(YBParallelPartitionKeys ppk)
*/
double average_key_size = ppk->total_key_size / ppk->total_key_count;
/* Account for the key length stored in the buffer */
average_key_size += sizeof(keylen_t);
average_key_size += sizeof(yb_keylen_t);
max_num_ranges =
floor(ppk->key_data_capacity / average_key_size) - ppk->key_count;
if (max_num_ranges < 16)
Expand All @@ -4518,7 +4518,7 @@ yb_fetch_partition_keys(YBParallelPartitionKeys ppk)
ppk->is_forward ? NULL : latest_key /* upper_bound_key */,
ppk->is_forward ? 0 : latest_key_size /* upper_bound_key_size */,
max_num_ranges, yb_parallel_range_size, ppk->is_forward,
(ppk->key_data_capacity / 3) - sizeof(keylen_t) /* max_key_length */,
(ppk->key_data_capacity / 3) - sizeof(yb_keylen_t) /* max_key_length */,
ppk_buffer_fetch_callback, &fkp));
SpinLockAcquire(&ppk->mutex);
/* Update fetch status */
Expand Down Expand Up @@ -4620,7 +4620,7 @@ ybParallelPrepare(YBParallelPartitionKeys ppk, Relation relation,
NULL /* upper_bound_key */, 0 /* upper_bound_key_size */,
YB_PARTITION_KEYS_DEFAULT_FETCH_SIZE,
yb_parallel_range_size, is_forward,
(ppk->key_data_capacity / 3) - sizeof(keylen_t),
(ppk->key_data_capacity / 3) - sizeof(yb_keylen_t),
ppk_buffer_initialize_callback, ppk));
/* Update fetch status, unless updated by the callback */
if (ppk->fetch_status == FETCH_STATUS_WORKING)
Expand All @@ -4647,8 +4647,8 @@ yb_copy_key_unsynchronized(YBParallelPartitionKeys ppk,
const char **bound,
size_t *bound_size)
{
keylen_t key_len;
memcpy(&key_len, KEY_LEN(ppk, ppk->low_offset), sizeof(keylen_t));
yb_keylen_t key_len;
memcpy(&key_len, KEY_LEN(ppk, ppk->low_offset), sizeof(yb_keylen_t));
*bound_size = key_len;
if (key_len > 0)
{
Expand Down
2 changes: 1 addition & 1 deletion src/postgres/src/backend/catalog/index.c
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ index_create(Relation heapRelation,
bool allow_system_table_mods,
bool is_internal,
Oid *constraintId,
OptSplit *split_options,
YbOptSplit *split_options,
const bool skip_index_backfill,
bool is_colocated,
Oid tablegroupId,
Expand Down
2 changes: 1 addition & 1 deletion src/postgres/src/backend/commands/indexcmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ DefineIndex(Oid relationId,
spec->roletype = ROLESPEC_CSTRING;
spec->rolename = pstrdup("postgres");

CreateTableGroupStmt *tablegroup_stmt = makeNode(CreateTableGroupStmt);
YbCreateTableGroupStmt *tablegroup_stmt = makeNode(YbCreateTableGroupStmt);
tablegroup_stmt->tablegroupname = tablegroup_name;
tablegroup_stmt->tablespacename = tablespace_name;
tablegroup_stmt->implicit = true;
Expand Down
Loading

0 comments on commit 6a56ce7

Please sign in to comment.