Skip to content

Commit 96ec8a8

Browse files
committed
[#28706] YSQL: run yb_pgindent
Summary: 1. Refactor code in YbRunWithPrefetcher to set YbcPgLastKnownCatalogVersionInfo fields one by one rather than assigning the whole struct. This is to avoid error on running yb_pgindent. 1. Update yb_typedefs.list using the method described in src/postgres/src/tools/pgindent/README. 1. Run yb_pgindent. 1. Make manual adjustments to some areas badly affected by yb_pgindent: - Add "YB" to comment in pgss_store. - Rename local variable is_tidvar to yb_is_tidvar in IsCTIDVar, and do other adjustments in the area. - Move function parameter comment after ");" for InitPostgres function call in PostgresMain. - YbctidListEval has a function call breaking after "(": restructure it. - yb_xcluster_ddl_replication/source_ddl_end_handler.h doesn't have "extern" for function declarations. Add it. There are probably more violations in other files in this directory, but don't bother with it now since they are not affected by this yb_pgindent run. 1. Run yb_pgindent one more time. Jira: DB-18409 Test Plan: jenkins Close: #28706 Reviewers: myang, asaha, amartsinchyk, hsunder Reviewed By: myang, asaha Subscribers: yql Differential Revision: https://phorge.dev.yugabyte.com/D46798
1 parent 8956839 commit 96ec8a8

File tree

45 files changed

+256
-199
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+256
-199
lines changed

src/postgres/contrib/pg_stat_statements/pg_stat_statements.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,10 +2002,14 @@ pgss_store(const char *query, uint64 queryId,
20022002
e->counters.jit_emission_time += INSTR_TIME_GET_MILLISEC(jitusage->emission_counter);
20032003
}
20042004

2005-
/* These stats are collected for both regular and utility statements, unlike EXPLAIN */
2005+
/*
2006+
* YB: These stats are collected for both regular and utility
2007+
* statements, unlike EXPLAIN
2008+
*/
20062009
if (kind == PGSS_EXEC)
20072010
{
20082011
YbInstrumentation yb_instr = {0};
2012+
20092013
YbUpdateSessionStats((YbInstrumentation *) &yb_instr);
20102014
e->counters.yb_counters.counters[YB_INT_DOCDB_READ_RPCS] +=
20112015
yb_instr.tbl_reads.count + yb_instr.index_reads.count;
@@ -2022,7 +2026,7 @@ pgss_store(const char *query, uint64 queryId,
20222026
(yb_instr.catalog_reads.wait_time) / 1000000.0;
20232027
e->counters.yb_counters.counters_dbl[YB_DBL_DOCDB_WAIT_TIME_MS] +=
20242028
(yb_instr.tbl_reads.wait_time + yb_instr.write_flushes.wait_time +
2025-
yb_instr.index_reads.wait_time) / 1000000.0;
2029+
yb_instr.index_reads.wait_time) / 1000000.0;
20262030
}
20272031

20282032
SpinLockRelease(&e->mutex);

src/postgres/src/backend/access/transam/parallel.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,6 +1467,7 @@ ParallelWorkerMain(Datum main_arg)
14671467
.parallel_leader_session_id = &fps->parallel_master_yb_session_state.session_id,
14681468
.shared_data = &fps->parallel_leader_pgproc->yb_shared_data
14691469
};
1470+
14701471
YbBackgroundWorkerInitializeConnectionByOid(fps->database_id,
14711472
fps->authenticated_user_id,
14721473
BGWORKER_BYPASS_ALLOWCONN,

src/postgres/src/backend/access/transam/xact.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,31 +2130,32 @@ YBBuildInitTransactionData()
21302130
return (YbcPgInitTransactionData)
21312131
{
21322132
.xact_start_timestamp = xactStartTimestamp,
2133-
.xact_read_only = XactReadOnly,
2134-
.xact_deferrable = XactDeferrable,
2135-
.enable_tracing = YBEnableTracing(),
2136-
.effective_pggate_isolation_level = YBGetEffectivePggateIsolationLevel(),
2137-
.read_from_followers_enabled = YBReadFromFollowersEnabled(),
2138-
.follower_read_staleness_ms = YBFollowerReadStalenessMs()
2133+
.xact_read_only = XactReadOnly,
2134+
.xact_deferrable = XactDeferrable,
2135+
.enable_tracing = YBEnableTracing(),
2136+
.effective_pggate_isolation_level = YBGetEffectivePggateIsolationLevel(),
2137+
.read_from_followers_enabled = YBReadFromFollowersEnabled(),
2138+
.follower_read_staleness_ms = YBFollowerReadStalenessMs()
21392139
};
21402140
}
21412141

21422142
static void
2143-
YBRunWithInitTransactionData(YbcStatus (*Callback)(const YbcPgInitTransactionData *))
2143+
YBRunWithInitTransactionData(YbcStatus (*Callback) (const YbcPgInitTransactionData *))
21442144
{
21452145
if (YBTransactionsEnabled())
21462146
{
21472147
const YbcPgInitTransactionData data =
2148-
{
2149-
.xact_start_timestamp = xactStartTimestamp,
2150-
.xact_read_only = XactReadOnly,
2151-
.xact_deferrable = XactDeferrable,
2152-
.enable_tracing = YBEnableTracing(),
2153-
.effective_pggate_isolation_level = YBGetEffectivePggateIsolationLevel(),
2154-
.read_from_followers_enabled = YBReadFromFollowersEnabled(),
2155-
.follower_read_staleness_ms = YBFollowerReadStalenessMs()
2156-
};
2157-
HandleYBStatus((*Callback)(&data));
2148+
{
2149+
.xact_start_timestamp = xactStartTimestamp,
2150+
.xact_read_only = XactReadOnly,
2151+
.xact_deferrable = XactDeferrable,
2152+
.enable_tracing = YBEnableTracing(),
2153+
.effective_pggate_isolation_level = YBGetEffectivePggateIsolationLevel(),
2154+
.read_from_followers_enabled = YBReadFromFollowersEnabled(),
2155+
.follower_read_staleness_ms = YBFollowerReadStalenessMs()
2156+
};
2157+
2158+
HandleYBStatus((*Callback) (&data));
21582159
}
21592160
}
21602161

src/postgres/src/backend/catalog/pg_publication.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,11 +1047,12 @@ YBGetPublicationOidsByNames(List *pubnames)
10471047

10481048
yb_publications = YBGetPublicationsByNames(pubnames, false /* missing_ok */ );
10491049

1050-
size_t table_idx = 0;
1050+
size_t table_idx = 0;
10511051

1052-
foreach (lc, yb_publications)
1052+
foreach(lc, yb_publications)
10531053
{
10541054
Publication *pub = (Publication *) lfirst(lc);
1055+
10551056
result[table_idx++] = pub->oid;
10561057
}
10571058

src/postgres/src/backend/commands/copyfrom.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,12 +798,13 @@ CopyFrom(CopyFromState cstate)
798798
else if (IsTransactionBlock() || YbIsBatchedExecution())
799799
{
800800
const char *context = IsTransactionBlock() ? "transaction block" : "batch of commands";
801+
801802
ereport(WARNING,
802803
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
803804
errmsg("ROWS_PER_TRANSACTION is not supported in a %s", context),
804805
errdetail("Defaulting to using one transaction for all statements in the %s.", context),
805806
errhint("Either run this COPY outside of a %s or set rows_per_transaction option to `0` "
806-
" to remove this warning.", context)));
807+
" to remove this warning.", context)));
807808
}
808809
else if (HasNonRITrigger(cstate->rel->trigdesc))
809810
ereport(WARNING,

src/postgres/src/backend/commands/dbcommands.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,8 +1105,8 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
11051105
* getting dropped while this operation is in progress.
11061106
*/
11071107
bool is_clone = strcmp(dbtemplate, "template0") != 0 && strcmp(dbtemplate, "template1") != 0;
1108-
LOCKMODE lockmode_srcdb = (is_clone ? AccessShareLock : ShareLock);
1109-
LOCKMODE lockmode_rel_db = (is_clone ? AccessShareLock : RowExclusiveLock);
1108+
LOCKMODE lockmode_srcdb = (is_clone ? AccessShareLock : ShareLock);
1109+
LOCKMODE lockmode_rel_db = (is_clone ? AccessShareLock : RowExclusiveLock);
11101110

11111111
if (!get_db_info(dbtemplate, lockmode_srcdb,
11121112
&src_dboid, &src_owner, &src_encoding,

src/postgres/src/backend/commands/explain.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -722,9 +722,10 @@ const char *yb_metric_event_label[] = {
722722

723723
#undef BUILD_METRIC_LABEL
724724

725-
typedef struct {
726-
bool is_required;
727-
bool is_dist;
725+
typedef struct
726+
{
727+
bool is_required;
728+
bool is_dist;
728729
ExplainFormat format;
729730
} YbExplainCommitStatState;
730731

@@ -1174,7 +1175,7 @@ YbExplainCommitStats(DestReceiver *dest)
11741175

11751176
ExplainState *es = NewExplainState();
11761177
TupOutputState *tstate = NULL;
1177-
TupleDesc tupdesc;
1178+
TupleDesc tupdesc;
11781179
YbInstrumentation yb_instr = {0};
11791180

11801181
es->rpc = yb_explain_commit_stat_state.is_dist;

src/postgres/src/backend/commands/tablecmds.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,7 +1956,7 @@ ExecuteTruncate(TruncateStmt *stmt, bool yb_is_top_level, List **yb_relids)
19561956
List *relids = NIL;
19571957
List *relids_logged = NIL;
19581958
ListCell *cell;
1959-
bool yb_only_temp_tables = true;
1959+
bool yb_only_temp_tables = true;
19601960

19611961
/*
19621962
* Open, exclusive-lock, and check all the explicitly-specified relations
@@ -3728,7 +3728,7 @@ SetRelationTableSpace(Relation rel,
37283728
otid = tuple->t_self;
37293729
rd_rel = (Form_pg_class) GETSTRUCT(tuple);
37303730

3731-
Oid yb_old_reltablespace = rd_rel->reltablespace;
3731+
Oid yb_old_reltablespace = rd_rel->reltablespace;
37323732

37333733
/* Update the pg_class row. */
37343734
rd_rel->reltablespace = (newTableSpaceId == MyDatabaseTableSpace) ?
@@ -3779,25 +3779,27 @@ SetRelationTableSpace(Relation rel,
37793779
{
37803780
List *indexIds = RelationGetIndexList(rel);
37813781
ListCell *lc;
3782-
Oid newPrimaryKeyTableSpaceId = (newTableSpaceId == MyDatabaseTableSpace) ?
3782+
Oid newPrimaryKeyTableSpaceId = (newTableSpaceId == MyDatabaseTableSpace) ?
37833783
InvalidOid : newTableSpaceId;
37843784

37853785
foreach(lc, indexIds)
37863786
{
37873787
Oid idxOid = lfirst_oid(lc);
37883788
Relation idxRel = RelationIdGetRelation(idxOid);
37893789
bool isPrimaryIndex = (idxRel != NULL &&
3790-
idxRel->rd_index &&
3791-
idxRel->rd_index->indisprimary);
3790+
idxRel->rd_index &&
3791+
idxRel->rd_index->indisprimary);
3792+
37923793
RelationClose(idxRel);
37933794

37943795
if (!isPrimaryIndex)
37953796
continue;
37963797

37973798
Relation idx_pg_class = table_open(RelationRelationId,
3798-
RowExclusiveLock);
3799+
RowExclusiveLock);
37993800
HeapTuple idx_tuple = SearchSysCacheCopy1(RELOID,
3800-
ObjectIdGetDatum(idxOid));
3801+
ObjectIdGetDatum(idxOid));
3802+
38013803
if (!HeapTupleIsValid(idx_tuple))
38023804
elog(ERROR, "cache lookup failed for relation %u", idxOid);
38033805
Form_pg_class idx_rd_rel = (Form_pg_class) GETSTRUCT(idx_tuple);
@@ -3809,7 +3811,7 @@ SetRelationTableSpace(Relation rel,
38093811

38103812
/* Update PK's pg_shdepend entry */
38113813
changeDependencyOnTablespace(RelationRelationId, idxOid,
3812-
newPrimaryKeyTableSpaceId);
3814+
newPrimaryKeyTableSpaceId);
38133815

38143816
heap_freetuple(idx_tuple);
38153817
table_close(idx_pg_class, RowExclusiveLock);

src/postgres/src/backend/executor/nodeTidscan.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -368,14 +368,14 @@ YbctidListEval(TidScanState *tidstate)
368368
int i;
369369

370370
arraydatum = ExecEvalExprSwitchContext(tidexpr->exprstate,
371-
econtext,
372-
&isNull);
371+
econtext,
372+
&isNull);
373373
if (isNull)
374374
continue;
375375

376376
itemarray = DatumGetArrayTypeP(arraydatum);
377377
deconstruct_array(itemarray, BYTEAOID, -1, false, TYPALIGN_INT,
378-
&ipdatums, &ipnulls, &ndatums);
378+
&ipdatums, &ipnulls, &ndatums);
379379
if (numYbctids + ndatums > numAllocYbctids)
380380
{
381381
numAllocYbctids = numYbctids + ndatums;
@@ -427,8 +427,9 @@ YbctidListEval(TidScanState *tidstate)
427427
static int
428428
ybctid_comparator(const void *a, const void *b)
429429
{
430-
return DatumGetInt32(
431-
DirectFunctionCall2(byteacmp, *(const Datum *) a, *(const Datum *) b));
430+
return DatumGetInt32(DirectFunctionCall2(byteacmp,
431+
*(const Datum *) a,
432+
*(const Datum *) b));
432433
}
433434

434435
/* ----------------------------------------------------------------
@@ -545,23 +546,25 @@ YbTidNext(TidScanState *node)
545546
*/
546547
if (node->ss.ss_currentScanDesc == NULL)
547548
{
548-
TidScan *plan = (TidScan *) node->ss.ps.plan;
549+
TidScan *plan = (TidScan *) node->ss.ps.plan;
549550
YbPushdownExprs *rel_pushdown =
550551
YbInstantiatePushdownExprs(&plan->yb_rel_pushdown, estate);
552+
551553
if (node->yb_tss_aggrefs)
552554
{
553555
TupleDesc tupdesc = CreateTemplateTupleDesc(list_length(node->yb_tss_aggrefs));
556+
554557
ExecInitScanTupleSlot(node->ss.ps.state, &node->ss, tupdesc, &TTSOpsVirtual);
555558
slot = node->ss.ss_ScanTupleSlot;
556559
}
557560
ybScan = ybcBeginScan(node->ss.ss_currentRelation,
558-
NULL, /* index */
561+
NULL, /* index */
559562
false, /* xs_want_itup */
560563
0, /* nkeys */
561564
NULL, /* key */
562565
(Scan *) plan,
563566
rel_pushdown,
564-
NULL, /* idx_pushdown */
567+
NULL, /* idx_pushdown */
565568
node->yb_tss_aggrefs,
566569
0, /* distinct_prefixlen */
567570
&estate->yb_exec_params,
@@ -751,8 +754,8 @@ ExecInitTidScan(TidScan *node, EState *estate, int eflags)
751754
ExecInitScanTupleSlot(estate, &tidstate->ss,
752755
RelationGetDescr(currentRelation),
753756
IsYBRelation(currentRelation) ?
754-
&TTSOpsVirtual :
755-
table_slot_callbacks(currentRelation));
757+
&TTSOpsVirtual :
758+
table_slot_callbacks(currentRelation));
756759

757760
/*
758761
* Initialize result type and projection.

src/postgres/src/backend/executor/nodeYbBitmapTablescan.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,9 @@ CreateYbBitmapTableScanDesc(YbBitmapTableScanState *scanstate)
264264
plan.recheck_local_quals = NULL;
265265

266266
yb_pushdown = YbInstantiatePushdownExprs((scanstate->work_mem_exceeded ?
267-
&plan.fallback_pushdown :
268-
&plan.rel_pushdown),
269-
scanstate->ss.ps.state);
267+
&plan.fallback_pushdown :
268+
&plan.rel_pushdown),
269+
scanstate->ss.ps.state);
270270

271271

272272
ybScan = ybcBeginScan(scanstate->ss.ss_currentRelation,
@@ -295,7 +295,7 @@ CreateYbBitmapTableScanDesc(YbBitmapTableScanState *scanstate)
295295
if (scanstate->recheck_required && !scanstate->work_mem_exceeded)
296296
{
297297
YbPushdownExprs *recheck_pushdown = YbInstantiatePushdownExprs(&plan.recheck_pushdown,
298-
scanstate->ss.ps.state);
298+
scanstate->ss.ps.state);
299299

300300
if (recheck_pushdown)
301301
{

0 commit comments

Comments
 (0)