Re: MAINTAIN privilege -- what do we need to un-revert it?
On Thu, 01 Aug 2024 11:31:53 -0700 Jeff Davis wrote: > On Wed, 2024-07-31 at 18:20 +0900, Yugo NAGATA wrote: > > I agree that it might not be important, but I think adding the flag > > would be > > also helpful for improving code-readability because it clarify the > > function > > is used in the two cases. I attached patch for this fix (patch 0003). > > Committed with one minor modification: I moved the boolean flag to be > near the other booleans rather than at the end. Thank you. > > > Sure. I fixed the patch to remove 'param' from both functions. (patch > > 0002) > > Committed, thank you. Thank you for committing them. Should not they be backported to REL_17_STABLE? > > > I also add the small refactoring around ExecCreateTableAs(). (patch > > 0001) > > > > - Remove matview-related codes from intorel_startup. > > Materialized views are no longer handled in this function. > > > > - RefreshMatViewByOid is moved to just after create_ctas_nodata > > call to improve code readability. > > > > I'm not sure the changes in intorel_startup() are correct. I tried > adding an Assert(into->viewQuery == NULL), and it fails because there's > another path I did not consider: "EXPLAIN ANALYZE CREATE MATERIALIZED > VIEW ...", which does not go through ExecCreateTableAs() but does go > through CreateIntoRelDestReceiver(). > > See: > > https://postgr.es/m/20444c382e6cb5e21e93c94d679d0198b0dba4dd.ca...@j-davis.com > > Should we refactor a bit and try to make EXPLAIN use the same code > paths? I overlooked that CreateIntoRelDestReceiver() is used from EXPLAIN. I saw the thread above and I agree that we should refactor it to make EXPLAIN consistent CREATE MATERIALIZED VIEW, but I suppose this should be discussed the other thread. I attached a updated patch removed the intorel_startup() part from. Regards, Yugo Nagata -- Yugo NAGATA >From 3609e85c288726e16dc851996a3b99e6179f43db Mon Sep 17 00:00:00 2001 From: Yugo Nagata Date: Fri, 2 Aug 2024 16:02:07 +0900 Subject: [PATCH v3] Small refactoring around ExecCreateTableAs Since commit b4da732f, the refresh logic is used to populate materialized views, so we can simplify the error message in ExecCreateTableAs. Also, RefreshMatViewByOid is moved to just after create_ctas_nodata call to improve code readability. --- src/backend/commands/createas.c | 34 - 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 36e192b79b..c71ff80188 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -228,9 +228,6 @@ ExecCreateTableAs(ParseState *pstate, CreateTableAsStmt *stmt, bool do_refresh = false; DestReceiver *dest; ObjectAddress address; - List *rewritten; - PlannedStmt *plan; - QueryDesc *queryDesc; /* Check if the relation exists or not */ if (CreateTableAsRelExists(stmt)) @@ -279,9 +276,25 @@ ExecCreateTableAs(ParseState *pstate, CreateTableAsStmt *stmt, * from running the planner before all dependencies are set up. */ address = create_ctas_nodata(query->targetList, into); + + /* + * For materialized views, reuse the REFRESH logic, which locks down + * security-restricted operations and restricts the search_path. This + * reduces the chance that a subsequent refresh will fail. + */ + if (do_refresh) + RefreshMatViewByOid(address.objectId, true, false, false, +pstate->p_sourcetext, qc); + } else { + List *rewritten; + PlannedStmt *plan; + QueryDesc *queryDesc; + + Assert(!is_matview); + /* * Parse analysis was done already, but we still have to run the rule * rewriter. We do not do AcquireRewriteLocks: we assume the query @@ -292,9 +305,7 @@ ExecCreateTableAs(ParseState *pstate, CreateTableAsStmt *stmt, /* SELECT should never rewrite to more or less than one SELECT query */ if (list_length(rewritten) != 1) - elog(ERROR, "unexpected rewrite result for %s", - is_matview ? "CREATE MATERIALIZED VIEW" : - "CREATE TABLE AS SELECT"); + elog(ERROR, "unexpected rewrite result for CREATE TABLE AS SELECT"); query = linitial_node(Query, rewritten); Assert(query->commandType == CMD_SELECT); @@ -339,17 +350,6 @@ ExecCreateTableAs(ParseState *pstate, CreateTableAsStmt *stmt, PopActiveSnapshot(); } - /* - * For materialized views, reuse the REFRESH logic, which locks down - * security-restricted operations and restricts the search_path. This - * reduces the chance that a subsequent refresh will fail. - */ - if (do_refresh) - { - RefreshMatViewByOid(address.objectId, true, false, false, - pstate->p_sourcetext, qc); - } - return address; } -- 2.34.1
Re: Adding OLD/NEW support to RETURNING
On Thu, Aug 1, 2024 at 7:33 PM Dean Rasheed wrote: > > On Mon, 29 Jul 2024 at 11:22, Dean Rasheed wrote: > > > > Trivial rebase, following c7301c3b6f. > > > > Rebased version, forced by a7f107df2b. Evaluating the input parameters > of correlated SubPlans in the referencing ExprState simplifies this > patch in a couple of places, since it no longer has to worry about > copying ExprState flags to a new ExprState. > hi. some minor issues. saveOld = changingPart && resultRelInfo->ri_projectReturning && resultRelInfo->ri_projectReturning->pi_state.flags & EEO_FLAG_HAS_OLD; if (resultRelInfo->ri_projectReturning && (processReturning || saveOld)) { } "saveOld" imply "resultRelInfo->ri_projectReturning" we can simplified it as if (processReturning || saveOld)) { } for projectReturning->pi_state.flags, we don't use EEO_FLAG_OLD_IS_NULL, EEO_FLAG_NEW_IS_NULL in ExecProcessReturning, we can do the following way. /* Make old/new tuples available to ExecProject, if required */ if (oldSlot) econtext->ecxt_oldtuple = oldSlot; else if (projectReturning->pi_state.flags & EEO_FLAG_HAS_OLD) econtext->ecxt_oldtuple = ExecGetAllNullSlot(estate, resultRelInfo); else econtext->ecxt_oldtuple = NULL; /* No references to OLD columns */ if (newSlot) econtext->ecxt_newtuple = newSlot; else if (projectReturning->pi_state.flags & EEO_FLAG_HAS_NEW) econtext->ecxt_newtuple = ExecGetAllNullSlot(estate, resultRelInfo); else econtext->ecxt_newtuple = NULL; /* No references to NEW columns */ /* * Tell ExecProject whether or not the OLD/NEW rows exist (needed for any * ReturningExpr nodes). */ if (oldSlot == NULL) projectReturning->pi_state.flags |= EEO_FLAG_OLD_IS_NULL; else projectReturning->pi_state.flags &= ~EEO_FLAG_OLD_IS_NULL; if (newSlot == NULL) projectReturning->pi_state.flags |= EEO_FLAG_NEW_IS_NULL; else projectReturning->pi_state.flags &= ~EEO_FLAG_NEW_IS_NULL; @@ -2620,6 +2620,13 @@ transformWholeRowRef(ParseState *pstate, * point, there seems no harm in expanding it now rather than during * planning. * + * Note that if the nsitem is an OLD/NEW alias for the target RTE (as can + * appear in a RETURNING list), its alias won't match the target RTE's + * alias, but we still want to make a whole-row Var here rather than a + * RowExpr, for consistency with direct references to the target RTE, and + * so that any dropped columns are handled correctly. Thus we also check + * p_returning_type here. + * makeWholeRowVar and subroutines only related to pg_type, but dropped column info is in pg_attribute. I don't understand "so that any dropped columns are handled correctly". ExecEvalSysVar, slot_getsysattr we have "Assert(attnum < 0);" but ExecEvalSysVar, while rowIsNull is true, we didn't do "Assert(attnum < 0);"
Re: why there is not VACUUM FULL CONCURRENTLY?
On Fri, 2 Aug 2024 at 11:09, Antonin Houska wrote: > > Kirill Reshke wrote: > > However, in general, the 3rd patch is really big, very hard to > > comprehend. Please consider splitting this into smaller (and > > reviewable) pieces. > > I'll try to move some preparation steps into separate diffs, but not sure if > that will make the main diff much smaller. I prefer self-contained patches, as > also explained in [3]. Thanks for sharing [3], it is a useful link. There is actually one more case when ACCESS EXCLUSIVE is held: during table rewrite (AT set TAM, AT set Tablespace and AT alter column type are some examples). This can be done CONCURRENTLY too, using the same logical replication approach, or do I miss something? I'm not saying we must do it immediately, this should be a separate thread, but we can do some preparation work here. I can see that a bunch of functions which are currently placed in cluster.c can be moved to something like logical_rewrite_heap.c. ConcurrentChange struct and apply_concurrent_insert function is one example of such. So, if this is the case, 0003 patch can be splitted in two: The first one is general utility code for logical table rewrite The second one with actual VACUUM CONCURRENTLY feature. What do you think?
Re: [Patch] remove duplicated smgrclose
Thanks, I have set my name in the Authors column of CF. Steven Junwang Zhao 于2024年8月2日周五 13:22写道: > Hi Steven, > > On Fri, Aug 2, 2024 at 12:12 PM Steven Niu wrote: > > > > Hi, Junwang, > > > > Thank you for the review and excellent summary in commit message! > > > > This is my first contribution to community, and not so familiar with the > overall process. > > After reading the process again, it looks like that I'm not qualified to > submit the patch to commitfest as I never had reviewed others' work. :( > > If so, could you please help to submit it to commitfest? > > > > https://commitfest.postgresql.org/49/5149/ > > I can not find your profile on commitfest so I left the author as empty, > have you ever registered? If you have a account, you can put your > name in the Authors list. > > > Best Regards, > > Steven > > > > Junwang Zhao 于2024年8月1日周四 20:32写道: > >> > >> Hi Steven, > >> > >> On Wed, Jul 31, 2024 at 11:16 AM Steven Niu wrote: > >> > > >> > Hello, hackers, > >> > > >> > I think there may be some duplicated codes. > >> > Function smgrDoPendingDeletes() calls both smgrdounlinkall() and > smgrclose(). > >> > But both functions would close SMgrRelation object, it's dupliacted > behavior? > >> > > >> > So I make this patch. Could someone take a look at it? > >> > > >> > Thanks for your help, > >> > Steven > >> > > >> > From Highgo.com > >> > > >> > > >> You change LGTM, but the patch seems not to be applied to HEAD, > >> I generate the attached v2 using `git format` with some commit message. > >> > >> -- > >> Regards > >> Junwang Zhao > > > > -- > Regards > Junwang Zhao >
Set query_id for query contained in utility statement
Hi all, Some utility statements like Explain, CreateTableAs and DeclareCursor contain a query which will be planned and executed. During post parse, only the top utility statement is jumbled, leaving the contained query without a query_id set. Explain does the query jumble in ExplainQuery but for the contained query but CreateTableAs and DeclareCursor were left with unset query_id. This leads to extensions relying on query_id like pg_stat_statements to not be able to track those nested queries as the query_id was 0. This patch fixes this by recursively jumbling queries contained in those utility statements during post_parse, setting the query_id for those contained queries and removing the need for ExplainQuery to do it for the Explain statements. Regards, Anthonin Bonnefoy v1-0001-Set-query_id-for-queries-contained-in-utility-sta.patch Description: Binary data
Small refactoring around vacuum_open_relation
I hate to be "that guy", but there are many places in sources where we use LOCKMODE lockmode; variable and exactly one where we use LOCKMODE lmode: it is vacuum_open_relation function. Is it worth a patch? v1-0001-Rename-vacuum_open_relation-argument-to-lockmode.patch Description: Binary data
Re: Logical Replication of sequences
On Thu, Aug 1, 2024 at 9:26 AM shveta malik wrote: > > On Mon, Jul 29, 2024 at 4:17 PM vignesh C wrote: > > > > Thanks for reporting this, these issues are fixed in the attached > > v20240730_2 version patch. > > I was reviewing the design of patch003, and I have a query. Do we need to even start an apply worker and create replication slot when subscription created is for 'sequences only'? IIUC, currently logical replication apply worker is the one launching sequence-sync worker whenever needed. I think it should be the launcher doing this job and thus apply worker may even not be needed for current functionality of sequence sync? Going forward when we implement incremental sync of sequences, then we may have apply worker started but now it is not needed. thanks Shveta
Re: v17 vs v16 performance comparison
01.08.2024 06:41, Tom Lane wrote: But beside that, I've found a separate regression. Bisecting for this degradation: Best pg-src-17--.* worse than pg-src-16--.* by 105.0 percents (356.63 > 173.96): s64da_tpcds.query95 Average pg-src-17--.* worse than pg-src-16--.* by 105.2 percents (357.79 > 174.38): s64da_tpcds.query95 pointed at f7816aec2. I'm not terribly concerned about that. The nature of planner changes like that is that some queries will get worse and some better, because the statistics and cost estimates we're dealing with are not perfect. It is probably worth drilling down into that test case to understand where the planner is going wrong, with an eye to future improvements; but I doubt it's something we need to address for v17. Please find attached two plans for that query [1]. (I repeated the benchmark for f7816aec2 and f7816aec2~1 five times and made sure that both plans are stable.) Meanwhile I've bisected another degradation: Best pg-src-17--.* worse than pg-src-16--.* by 11.3 percents (7.17 > 6.44): job.query6f and came to the commit b7b0f3f27 again. [1] https://github.com/swarm64/s64da-benchmark-toolkit/blob/master/benchmarks/tpcds/queries/queries_10/95.sql Best regards, Alexander[{ "Query Text": "-- RNGSEED: 1\n\n-- EXPLAIN (FORMAT JSON)\nwith ws_wh as\n(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2\n from web_sales ws1,web_sales ws2\n where ws1.ws_order_number = ws2.ws_order_number\n and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk)\n select\n count(distinct ws_order_number) as \"order count\"\n ,sum(ws_ext_ship_cost) as \"total shipping cost\"\n ,sum(ws_net_profit) as \"total net profit\"\nfrom\n web_sales ws1\n ,date_dim\n ,customer_address\n ,web_site\nwhere\nd_date between '2000-3-01' and\n (cast('2000-3-01' as date) + 60)\nand ws1.ws_ship_date_sk = d_date_sk\nand ws1.ws_ship_addr_sk = ca_address_sk\nand ca_state = 'GA'\nand ws1.ws_web_site_sk = web_site_sk\nand web_company_name = 'pri'\nand ws1.ws_order_number in (select ws_order_number\n from ws_wh)\nand ws1.ws_order_number in (select wr_order_number\n from web_returns,ws_wh\nwhere wr_order_number = ws_wh.ws_order_number)\norder by count(distinct ws_order_number)\nlimit 100;\n", "Plan": { "Node Type": "Limit", "Parallel Aware": false, "Async Capable": false, "Startup Cost": 1244768.73, "Total Cost": 1244768.73, "Plan Rows": 1, "Plan Width": 72, "Actual Startup Time": 277228.286, "Actual Total Time": 277228.294, "Actual Rows": 1, "Actual Loops": 1, "Output": ["(count(DISTINCT ws1.ws_order_number))", "(sum(ws1.ws_ext_ship_cost))", "(sum(ws1.ws_net_profit))"], "Plans": [ { "Node Type": "Hash Join", "Parent Relationship": "InitPlan", "Subplan Name": "CTE ws_wh", "Parallel Aware": false, "Async Capable": false, "Join Type": "Inner", "Startup Cost": 76039.92, "Total Cost": 443675.28, "Plan Rows": 17135538, "Plan Width": 12, "Actual Startup Time": 380.616, "Actual Total Time": 3160.748, "Actual Rows": 13341520, "Actual Loops": 1, "Output": ["ws1_1.ws_order_number", "ws1_1.ws_warehouse_sk", "ws2.ws_warehouse_sk"], "Inner Unique": false, "Hash Cond": "(ws1_1.ws_order_number = ws2.ws_order_number)", "Join Filter": "(ws1_1.ws_warehouse_sk <> ws2.ws_warehouse_sk)", "Rows Removed by Join Filter": 4787014, "Plans": [ { "Node Type": "Seq Scan", "Parent Relationship": "Outer", "Parallel Aware": false, "Async Capable": false, "Relation Name": "web_sales", "Schema": "public", "Alias": "ws1_1", "Startup Cost": 0.00, "Total Cost": 52382.52, "Plan Rows": 1441952, "Plan Width": 8, "Actual Startup Time": 0.013, "Actual Total Time": 223.129, "Actual Rows": 1441948, "Actual Loops": 1, "Output": ["ws1_1.ws_order_number", "ws1_1.ws_warehouse_sk"] }, { "Node Type": "Hash", "Parent Relationship": "Inner", "Parallel Aware": false, "Async Capable": false, "Startup Cost": 52382.52, "Total Cost": 52382.52, "Plan Rows": 1441952, "Plan Width": 8, "Actual Startup Time": 379.625, "Actual Total Time": 379.626, "Actual Rows": 1441948, "Actual Loops": 1, "Output": ["ws2.ws_warehouse_sk", "ws2.ws_order_number"], "Hash Buckets": 262144, "Original Hash Buckets": 262144, "Hash Batches": 16, "Original Hash Batches": 16, "Peak Memory Usage": 5602, "Plans"
Re: Logical Replication of sequences
On Fri, Aug 2, 2024 at 2:24 PM shveta malik wrote: > > On Thu, Aug 1, 2024 at 9:26 AM shveta malik wrote: > > > > On Mon, Jul 29, 2024 at 4:17 PM vignesh C wrote: > > > > > > Thanks for reporting this, these issues are fixed in the attached > > > v20240730_2 version patch. > > > > > I was reviewing the design of patch003, and I have a query. Do we need > to even start an apply worker and create replication slot when > subscription created is for 'sequences only'? IIUC, currently logical > replication apply worker is the one launching sequence-sync worker > whenever needed. I think it should be the launcher doing this job and > thus apply worker may even not be needed for current functionality of > sequence sync? Going forward when we implement incremental sync of > sequences, then we may have apply worker started but now it is not > needed. > Also, can we please mention the state change and 'who does what' atop sequencesync.c file similar to what we have atop tablesync.c file otherwise it is difficult to figure out the flow. thanks Shveta
Re: [PATCH] Add min/max aggregate functions to BYTEA
> On 24 Jul 2024, at 17:42, Marat Bukharov wrote: > > V5 patch. I've added more tests with different bytea sizes Hi Marat! This looks like a nice feature to have. I’ve took a look into the patch and have few suggestions: 0. Please write more descriptive commit message akin to [0] 1. Use oids from development range 8000- 2. Replace VARDATA_ANY\memcmp dance with a call to varstrfastcmp_c(). Thank you! Best regards, Andrey Borodin. [0] https://github.com/postgres/postgres/commit/a0f1fce80c03
Re: Small refactoring around vacuum_open_relation
On Fri, Aug 2, 2024 at 1:55 PM Kirill Reshke wrote: > > I hate to be "that guy", but there are many places in sources where we use > LOCKMODE lockmode; variable and exactly one where we use LOCKMODE > lmode: it is vacuum_open_relation function. There are more instances of LOCKMODE lmode; I spotted one in plancat.c as well. Case1: toast_get_valid_index(Oid toastoid, LOCKMODE lock) toast_close_indexes(Relation *toastidxs, int num_indexes, LOCKMODE lock) GetLockmodeName(LOCKMETHODID lockmethodid, LOCKMODE mode) LOCKMODE mode = 0; Case 2: qualified variable names like LOCKMODE heapLockmode; LOCKMODE memlockmode; LOCKMODE table_lockmode; LOCKMODE parentLockmode; LOCKMODE cmd_lockmode = AccessExclusiveLock; /* default for compiler */ LOCK_PRINT(const char *where, const LOCK *lock, LOCKMODE type) case3: some that have two LOCKMODE instances like DoLockModesConflict(LOCKMODE mode1, LOCKMODE mode2) > Is it worth a patch? When I see a variable with name lockmode, I know it's of type LOCKMODE. So changing the Case1 may be worth it. It's not a whole lot of code churn as well. May be patch backbranches. Case2 we should leave as is since the variable name has lockmode in it. Case3, worth changing to lockmode1 and lockmode2. -- Best Wishes, Ashutosh Bapat
Re: Wrong results with grouping sets
I've been looking at cases where there are grouping-set keys that reduce to Consts, and I noticed a plan with v11 patch that is not very great. explain (verbose, costs off) select 1 as one group by rollup(one) order by one nulls first; QUERY PLAN --- Sort Output: (1) Sort Key: (1) NULLS FIRST -> GroupAggregate Output: (1) Group Key: (1) Group Key: () -> Sort Output: (1) Sort Key: (1) -> Result Output: 1 (12 rows) The Sort operation below the Agg node is unnecessary because the grouping key is actually a Const. This plan results from wrapping the Const in a PlaceHolderVar to carry the nullingrel bit of the RTE_GROUP RT index, as it can be nulled by the grouping step. Although we remove this nullingrel bit when generating the groupClause pathkeys since we know the groupClause is logically below the grouping step, we do not unwrap the PlaceHolderVar. This suggests that we might need a mechanism to unwrap PHVs when safe. 0003 includes a flag in PlaceHolderVar to indicate whether it is safe to remove the PHV and use its contained expression instead when its phnullingrels becomes empty. Currently it is set true only in cases where the PHV is used to carry the nullingrel bit of the RTE_GROUP RT index. With 0003 the plan above becomes more reasonable: explain (verbose, costs off) select 1 as one group by rollup(one) order by one nulls first; QUERY PLAN - Sort Output: (1) Sort Key: (1) NULLS FIRST -> GroupAggregate Output: (1) Group Key: 1 Group Key: () -> Result Output: 1 (9 rows) This could potentially open up opportunities for optimization by unwrapping PHVs in other cases. As an example, consider explain (costs off) select * from t t1 left join lateral (select t1.a as x, * from t t2) s on true where t1.a = s.a; QUERY PLAN Nested Loop -> Seq Scan on t t1 -> Seq Scan on t t2 Filter: (t1.a = a) (4 rows) The target entry s.x is wrapped in a PHV that contains lateral reference to t1, which forces us to resort to nestloop join. However, since the left join has been reduced to an inner join, we should be able to remove this PHV and use merge or hash joins instead. I did not implement this optimization in 0003. It seems that it should be addressed in a separate patch. Thanks Richard v12-0001-Introduce-an-RTE-for-the-grouping-step.patch Description: Binary data v12-0002-Mark-expressions-nullable-by-grouping-sets.patch Description: Binary data v12-0003-Unwrap-a-PlaceHolderVar-when-safe.patch Description: Binary data
Re: Small refactoring around vacuum_open_relation
Thanks for review! On Fri, 2 Aug 2024 at 14:31, Ashutosh Bapat wrote: > > On Fri, Aug 2, 2024 at 1:55 PM Kirill Reshke wrote: > > > > I hate to be "that guy", but there are many places in sources where we use > > LOCKMODE lockmode; variable and exactly one where we use LOCKMODE > > lmode: it is vacuum_open_relation function. > > There are more instances of LOCKMODE lmode; I spotted one in plancat.c as > well. Nice catch! > Case1: > toast_get_valid_index(Oid toastoid, LOCKMODE lock) > toast_close_indexes(Relation *toastidxs, int num_indexes, LOCKMODE lock) > GetLockmodeName(LOCKMETHODID lockmethodid, LOCKMODE mode) > LOCKMODE mode = 0; > Case 2: > qualified variable names like > LOCKMODE heapLockmode; > LOCKMODE memlockmode; > LOCKMODE table_lockmode; > LOCKMODE parentLockmode; > LOCKMODE cmd_lockmode = AccessExclusiveLock; /* default for compiler */ > LOCK_PRINT(const char *where, const LOCK *lock, LOCKMODE type) > > case3: some that have two LOCKMODE instances like > DoLockModesConflict(LOCKMODE mode1, LOCKMODE mode2) Nice catch! > > Is it worth a patch? > > When I see a variable with name lockmode, I know it's of type > LOCKMODE. So changing the Case1 may be worth it. It's not a whole lot > of code churn as well. May be patch backbranches. > > Case2 we should leave as is since the variable name has lockmode in it. +1 > Case3, worth changing to lockmode1 and lockmode2. Agree > -- > Best Wishes, > Ashutosh Bapat Attached v2 patch with your suggestions addressed. v2-0001-Rename-LOCKMODE-type-vairables-to-lockmode.patch Description: Binary data
Remove obsolete RECHECK keyword completely
I propose to remove the obsolete RECHECK keyword completely. This used to be part of CREATE OPERATOR CLASS and ALTER OPERATOR FAMILY, but it has done nothing (except issue a NOTICE) since PostgreSQL 8.4. Commit 30e7c175b81 removed support for dumping from pre-9.2 servers, so this no longer serves any need, it seems to me. This now removes it completely, and you'd get a normal parse error if you used it. From 284e0a8f4729d9d6507ae0029cad637b7d870d41 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Fri, 2 Aug 2024 12:37:33 +0200 Subject: [PATCH] Remove obsolete RECHECK keyword completely This used to be part of CREATE OPERATOR CLASS and ALTER OPERATOR FAMILY, but it has done nothing (except issue a NOTICE) since PostgreSQL 8.4. Commit 30e7c175b81 removed support for dumping from pre-9.2 servers, so this no longer serves any need. This now removes it completely, and you'd get a normal parse error if you used it. --- doc/src/sgml/ref/alter_opfamily.sgml | 8 -- doc/src/sgml/ref/create_opclass.sgml | 8 -- src/backend/parser/gram.y | 26 +++ src/include/parser/kwlist.h | 1 - .../isolation/specs/merge-match-recheck.spec | 2 +- 5 files changed, 4 insertions(+), 41 deletions(-) diff --git a/doc/src/sgml/ref/alter_opfamily.sgml b/doc/src/sgml/ref/alter_opfamily.sgml index b2e5b9b72ec..5c4c2e579f5 100644 --- a/doc/src/sgml/ref/alter_opfamily.sgml +++ b/doc/src/sgml/ref/alter_opfamily.sgml @@ -273,14 +273,6 @@ Notes is likely to be inlined into the calling query, which will prevent the optimizer from recognizing that the query matches an index. - - - Before PostgreSQL 8.4, the OPERATOR - clause could include a RECHECK option. This is no longer - supported because whether an index operator is lossy is now - determined on-the-fly at run time. This allows efficient handling of - cases where an operator might or might not be lossy. - diff --git a/doc/src/sgml/ref/create_opclass.sgml b/doc/src/sgml/ref/create_opclass.sgml index f1d6a4cbbe2..2d560b68658 100644 --- a/doc/src/sgml/ref/create_opclass.sgml +++ b/doc/src/sgml/ref/create_opclass.sgml @@ -269,14 +269,6 @@ Notes is likely to be inlined into the calling query, which will prevent the optimizer from recognizing that the query matches an index. - - - Before PostgreSQL 8.4, the OPERATOR - clause could include a RECHECK option. This is no longer - supported because whether an index operator is lossy is now - determined on-the-fly at run time. This allows efficient handling of - cases where an operator might or might not be lossy. - diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index a043fd4c669..c3f25582c38 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -495,7 +495,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query); %type opt_instead %type opt_unique opt_verbose opt_full -%type opt_freeze opt_analyze opt_default opt_recheck +%type opt_freeze opt_analyze opt_default %type opt_binary copy_delimiter %type copy_from opt_program @@ -770,7 +770,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query); QUOTE QUOTES - RANGE READ REAL REASSIGN RECHECK RECURSIVE REF_P REFERENCES REFERENCING + RANGE READ REAL REASSIGN RECURSIVE REF_P REFERENCES REFERENCING REFRESH REINDEX RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA RESET RESTART RESTRICT RETURN RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROLLUP ROUTINE ROUTINES ROW ROWS RULE @@ -6622,7 +6622,7 @@ opclass_item_list: ; opclass_item: - OPERATOR Iconst any_operator opclass_purpose opt_recheck + OPERATOR Iconst any_operator opclass_purpose { CreateOpClassItem *n = makeNode(CreateOpClassItem); ObjectWithArgs *owa = makeNode(ObjectWithArgs); @@ -6636,7 +6636,6 @@ opclass_item: $$ = (Node *) n; } | OPERATOR Iconst operator_with_argtypes opclass_purpose - opt_recheck { CreateOpClassItem *n = makeNode(CreateOpClassItem); @@ -6688,23 +6687,6 @@ opclass_purpose: FOR SEARCH { $$ = NIL; } | /*EMPTY*/ { $$ = NIL; } ; -opt_recheck: RECHECK - { - /* -* RECHECK no longer does anything in opclass definitions, -* but we still accept it to ease porting o
Re: Conflict detection and logging in logical replication
On Thu, Aug 1, 2024 at 5:23 PM Amit Kapila wrote: > > On Thu, Aug 1, 2024 at 2:26 PM Hayato Kuroda (Fujitsu) > wrote: > > > > 04. general > > > > According to the documentation [1], there is another constraint "exclude", > > which > > can cause another type of conflict. But this pattern cannot be logged in > > detail. > > > > As per docs, "exclusion constraints can specify constraints that are > more general than simple equality", so I don't think it satisfies the > kind of conflicts we are trying to LOG and then in the future patch > allows automatic resolution for the same. For example, when we have > last_update_wins strategy, we will replace the rows with remote rows > when the key column values match which shouldn't be true in general > for exclusion constraints. Similarly, we don't want to consider other > constraint violations like CHECK to consider as conflicts. We can > always extend the basic functionality for more conflicts if required > but let's go with reporting straight-forward stuff first. > It is better to document that exclusion constraints won't be supported. We can even write a comment in the code and or commit message that we can extend it in the future. * + * Return true if the commit timestamp data was found, false otherwise. + */ +bool +GetTupleCommitTs(TupleTableSlot *localslot, TransactionId *xmin, + RepOriginId *localorigin, TimestampTz *localts) This API returns both xmin and commit timestamp, so wouldn't it be better to name it as GetTupleTransactionInfo or something like that? I have made several changes in the attached top-up patch. These include changes in the comments, docs, function names, etc. -- With Regards, Amit Kapila. diff --git a/doc/src/sgml/logical-replication.sgml b/doc/src/sgml/logical-replication.sgml index c1f6f1aaa8..dfbff3de02 100644 --- a/doc/src/sgml/logical-replication.sgml +++ b/doc/src/sgml/logical-replication.sgml @@ -1585,17 +1585,17 @@ test_sub=# SELECT * FROM t1 ORDER BY id; Additional logging is triggered in the following conflict - scenarios: + cases: insert_exists Inserting a row that violates a NOT DEFERRABLE - unique constraint. Note that to obtain the origin and commit - timestamp details of the conflicting key in the log, ensure that + unique constraint. Note that to log the origin and commit + timestamp details of the conflicting key, track_commit_timestamp - is enabled. In this scenario, an error will be raised until the + should be enabled. In this case, an error will be raised until the conflict is resolved manually. @@ -1605,10 +1605,10 @@ test_sub=# SELECT * FROM t1 ORDER BY id; The updated value of a row violates a NOT DEFERRABLE - unique constraint. Note that to obtain the origin and commit - timestamp details of the conflicting key in the log, ensure that + unique constraint. Note that to log the origin and commit + timestamp details of the conflicting key, track_commit_timestamp - is enabled. In this scenario, an error will be raised until the + is enabled. In this case, an error will be raised until the conflict is resolved manually. Note that when updating a partitioned table, if the updated row value satisfies another partition constraint resulting in the row being inserted into a @@ -1720,10 +1720,10 @@ CONTEXT: processing remote data for replication origin "pg_16395" during "INSER commit timestamp can be seen in the DETAIL line of the log. But note that this information is only available when track_commit_timestamp - is enabled. Users can use these information to make decisions on whether to - retain the local change or adopt the remote alteration. For instance, the - DETAIL line in above log indicates that the existing row was - modified by a local change, users can manually perform a remote-change-win + is enabled. Users can use this information to decide whether to retain the + local change or adopt the remote alteration. For instance, the + DETAIL line in the above log indicates that the existing + row was modified locally. Users can manually perform a remote-change-win resolution by deleting the local row. diff --git a/src/backend/executor/execReplication.c b/src/backend/executor/execReplication.c index ad3eda1459..34050a3bae 100644 --- a/src/backend/executor/execReplication.c +++ b/src/backend/executor/execReplication.c @@ -475,13 +475,13 @@ retry: } /* - * Find the tuple that violates the passed in unique index constraint - * (conflictindex). + * Find the tuple that violates the passed unique index (conflictindex). * - * If no conflict is found, return false and set *conflictslot to NULL. - * Otherwise return true, and the conflicting tuple is locked and returned in - * *conflictslot. The lock is essential to allow retrying to find the - * conflicting tu
Re: Memory growth observed with C++ application consuming libpq.dll on Windows
Hi Yasir, Are you looking for a fully functional sample program or only the APIs from libpq library that our product uses? I am asking this because if the requirement is to have a sample code, then I will have to work on creating one on the same lines as our product. Rajesh On Thu, Aug 1, 2024 at 5:27 PM Yasir wrote: > Hi Rajesh, > > Can you please attach a sample code snippet showing libpq's functions > being called? It will help to identify the libpq's functions to investigate > further for a potential mem leak. > > Regards... > > Yasir Hussain > > On Thu, Aug 1, 2024 at 4:30 PM Rajesh Kokkonda > wrote: > >> Hi, >> >> We are seeing a gradual growth in the memory consumption of our process >> on Windows. Ours is a C++ application that directly loads libpq.dll and >> handles the queries and functions. We use setSingleRowMethod to limit the >> number of rows returned simultaneously to the application. We do not >> observe any memory increase when the application is run on Linux. There is >> no code difference between Windows and Linux from the >> application standpoint. We ran valgrind against our application on Linux >> and found no memory leaks. Since the same code is being used on Windows as >> well, we do not suspect any memory leak there. The question is if there >> are any known memory leaks with the version of the library we are using on >> Windows. Kindly let us know. >> >> The version of the library on Linux is libpq.so.5.16 >> >> The windows version of the library is 16.0.3.0 >> >> >> [image: image.png] >> >> Thanks, >> Rajesh >> >
Re: Memory growth observed with C++ application consuming libpq.dll on Windows
On Fri, Aug 2, 2024 at 1:53 PM Rajesh Kokkonda wrote: > Hi Yasir, > > Are you looking for a fully functional sample program or only the APIs > from libpq library that our product uses? I am asking this because if the > requirement is to have a sample code, then I will have to work on creating > one on the same lines as our product. > > A functional sample is always best and preferred, however, only APIs used by your product would also be sufficient. Rajesh > > On Thu, Aug 1, 2024 at 5:27 PM Yasir wrote: > >> Hi Rajesh, >> >> Can you please attach a sample code snippet showing libpq's functions >> being called? It will help to identify the libpq's functions to investigate >> further for a potential mem leak. >> >> Regards... >> >> Yasir Hussain >> >> On Thu, Aug 1, 2024 at 4:30 PM Rajesh Kokkonda < >> rajeshk.kokko...@gmail.com> wrote: >> >>> Hi, >>> >>> We are seeing a gradual growth in the memory consumption of our process >>> on Windows. Ours is a C++ application that directly loads libpq.dll and >>> handles the queries and functions. We use setSingleRowMethod to limit the >>> number of rows returned simultaneously to the application. We do not >>> observe any memory increase when the application is run on Linux. There is >>> no code difference between Windows and Linux from the >>> application standpoint. We ran valgrind against our application on Linux >>> and found no memory leaks. Since the same code is being used on Windows as >>> well, we do not suspect any memory leak there. The question is if there >>> are any known memory leaks with the version of the library we are using on >>> Windows. Kindly let us know. >>> >>> The version of the library on Linux is libpq.so.5.16 >>> >>> The windows version of the library is 16.0.3.0 >>> >>> >>> [image: image.png] >>> >>> Thanks, >>> Rajesh >>> >>
Re: Psql meta-command conninfo+
Hi, I have read the entire thread discussion. I understood the importance of this enhancement related to /conninfo+ meta command. I really appreciate the efforts of Maiquel and suggestions made by the reviewers. According to best of my understanding, libpq API should be used instead of creating server query for conninfo+ meta command. Building on the patch (v29) provided by Maiquel, I made changes to retrieve some extra information related to connection from libpq API. Extra information includes: - Protocol Version - SSL Connection - GSSAPI Authenticated - Client Encoding - Server Encoding - Session User - Backend PID Output of \conninfo+: 1. $ bin/psql --port=5430 postgres -h localhost psql (18devel) Type "help" for help. postgres=# \conninfo+ You are connected to database "postgres" as user "hunaid" on host "localhost" (address "127.0.0.1") at port "5430". Protocol Version: 3 SSL Connection: no GSSAPI Authenticated: no Client Encoding: UTF8 Server Encoding: UTF8 Session User: hunaid Backend PID: 163816 I have also edited the documentation and added it to the patch. Please let me know if any changes are required. Regards, Hunaid Sohail On Wed, Jun 5, 2024 at 5:32â¯PM Maiquel Grassi wrote: > From a quick skim of the latest messages in this thread, it sounds like > there are a couple of folks who think \conninfo (and consequently > \conninfo+) should only report values from the libpq API. I think they > would prefer server-side information to be provided via a system view or > maybe an entirely new psql meta-command. > > IIUC a new system view would more-or-less just gather information from > other system views and functions. A view would be nice because it could be > used outside psql, but I'm not sure to what extent we are comfortable > adding system views built on other system views. Something like > \sessioninfo (as proposed by Sami) would look more similar to what you have > in your latest patch, i.e., we'd teach psql about a complicated query for > gathering all this disparate information. > > IMHO a good way to help move this forward is to try implementing it as a > system view so that we can compare the two approaches. I've had luck in > the past with implementing something a couple different ways to help drive > consensus. > > --//-- > > Great Nathan, we can follow that path of the view. I leave it open for > anyone in the thread who has been following from the beginning to start the > development of the view. Even you, if you have the interest and time to do > it. At this exact moment, I am involved in a "my baby born" project, so I > am unable to stop to look into this. If someone wants to start, I would > appreciate it. > Regards, > Maiquel Grassi. > ÿþd i f f - - g i t a / d o c / s r c / s g m l / r e f / p s q l - r e f . s g m l b / d o c / s r c / s g m l / r e f / p s q l - r e f . s g m l i n d e x 0 7 4 1 9 a 3 b 9 2 . . f b 3 d 5 2 f b 1 6 1 0 0 6 4 4 - - - a / d o c / s r c / s g m l / r e f / p s q l - r e f . s g m l + + + b / d o c / s r c / s g m l / r e f / p s q l - r e f . s g m l @ @ - 1 0 3 0 , 1 1 + 1 0 3 0 , 2 9 @ @ I N S E R T I N T O t b l 1 V A L U E S ( $ 1 , $ 2 ) \ b i n d ' f i r s t v a l u e ' ' s e c o n d v a l u e ' \ g <