Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2c3e475

Browse files
committed
Fix a couple of problems in pg_get_statisticsextdef
There was a thinko whereby we tested the wrong tuple after fetching itfrom cache; avoid that by using generate_relation_name instead, which issimpler. Also, the statistics name was not qualified, so add that. (Itcould be argued that qualification should be conditional on the schemanot being on search path. We can add that later, but at least this formis correct.)Author: David Rowley, Álvaro HerreraDiscussion:https://postgr.es/m/CAKJS1f8RjLeVZJ2+93pdQGuZJeBF-ifsHaFMR-q-6-Z0qxA8cA@mail.gmail.com
1 parentb563594 commit2c3e475

File tree

5 files changed

+23
-15
lines changed

5 files changed

+23
-15
lines changed

‎src/backend/utils/adt/ruleutils.c

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,11 +1448,10 @@ static char *
14481448
pg_get_statisticsext_worker(Oidstatextid,boolmissing_ok)
14491449
{
14501450
Form_pg_statistic_extstatextrec;
1451-
Form_pg_classpgclassrec;
14521451
HeapTuplestatexttup;
1453-
HeapTuplepgclasstup;
14541452
StringInfoDatabuf;
14551453
intcolno;
1454+
char*nsp;
14561455

14571456
statexttup=SearchSysCache1(STATEXTOID,ObjectIdGetDatum(statextid));
14581457

@@ -1465,20 +1464,12 @@ pg_get_statisticsext_worker(Oid statextid, bool missing_ok)
14651464

14661465
statextrec= (Form_pg_statistic_ext)GETSTRUCT(statexttup);
14671466

1468-
pgclasstup=SearchSysCache1(RELOID,ObjectIdGetDatum(statextrec->starelid));
1469-
1470-
if (!HeapTupleIsValid(statexttup))
1471-
{
1472-
ReleaseSysCache(statexttup);
1473-
elog(ERROR,"cache lookup failed for relation %u",statextrec->starelid);
1474-
}
1475-
1476-
pgclassrec= (Form_pg_class)GETSTRUCT(pgclasstup);
1477-
14781467
initStringInfo(&buf);
14791468

1469+
nsp=get_namespace_name(statextrec->stanamespace);
14801470
appendStringInfo(&buf,"CREATE STATISTICS %s ON (",
1481-
quote_identifier(NameStr(statextrec->staname)));
1471+
quote_qualified_identifier(nsp,
1472+
NameStr(statextrec->staname)));
14821473

14831474
for (colno=0;colno<statextrec->stakeys.dim1;colno++)
14841475
{
@@ -1494,10 +1485,9 @@ pg_get_statisticsext_worker(Oid statextid, bool missing_ok)
14941485
}
14951486

14961487
appendStringInfo(&buf,") FROM %s",
1497-
quote_identifier(NameStr(pgclassrec->relname)));
1488+
generate_relation_name(statextrec->starelid,NIL));
14981489

14991490
ReleaseSysCache(statexttup);
1500-
ReleaseSysCache(pgclasstup);
15011491

15021492
returnbuf.data;
15031493
}

‎src/test/regress/expected/rules.out

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3167,6 +3167,12 @@ SELECT pg_get_ruledef(0);
31673167

31683168
(1 row)
31693169

3170+
SELECT pg_get_statisticsextdef(0);
3171+
pg_get_statisticsextdef
3172+
-------------------------
3173+
3174+
(1 row)
3175+
31703176
SELECT pg_get_triggerdef(0);
31713177
pg_get_triggerdef
31723178
-------------------

‎src/test/regress/expected/stats_ext.out

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ CREATE STATISTICS ab1_a_b_stats ON (a, b) FROM ab1;
55
DROP STATISTICS ab1_a_b_stats;
66
CREATE SCHEMA regress_schema_2;
77
CREATE STATISTICS regress_schema_2.ab1_a_b_stats ON (a, b) FROM ab1;
8+
-- Let's also verify the pg_get_statisticsextdef output looks sane.
9+
SELECT pg_get_statisticsextdef(oid) FROM pg_statistic_ext WHERE staname = 'ab1_a_b_stats';
10+
pg_get_statisticsextdef
11+
---------------------------------------------------------------------
12+
CREATE STATISTICS regress_schema_2.ab1_a_b_stats ON (a, b) FROM ab1
13+
(1 row)
14+
815
DROP STATISTICS regress_schema_2.ab1_a_b_stats;
916
-- Ensure statistics are dropped when columns are
1017
CREATE STATISTICS ab1_b_c_stats ON (b, c) FROM ab1;

‎src/test/regress/sql/rules.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,7 @@ SELECT pg_get_constraintdef(0);
11501150
SELECT pg_get_functiondef(0);
11511151
SELECT pg_get_indexdef(0);
11521152
SELECT pg_get_ruledef(0);
1153+
SELECT pg_get_statisticsextdef(0);
11531154
SELECT pg_get_triggerdef(0);
11541155
SELECT pg_get_viewdef(0);
11551156
SELECT pg_get_function_arguments(0);

‎src/test/regress/sql/stats_ext.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ DROP STATISTICS ab1_a_b_stats;
77

88
CREATESCHEMAregress_schema_2;
99
CREATE STATISTICSregress_schema_2.ab1_a_b_statsON (a, b)FROM ab1;
10+
11+
-- Let's also verify the pg_get_statisticsextdef output looks sane.
12+
SELECT pg_get_statisticsextdef(oid)FROM pg_statistic_extWHERE staname='ab1_a_b_stats';
13+
1014
DROP STATISTICSregress_schema_2.ab1_a_b_stats;
1115

1216
-- Ensure statistics are dropped when columns are

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp