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

Commitd99d58c

Browse files
committed
Complete tab completion for DROP STATISTICS
Tab-completing DROP STATISTICS would only work if you started writingthe schema name containing the statistics object, because the visibilityclause was missing. To add it, we need to add SQL-callable support fortesting visibility of a statistics object, like all other object typesalready have.Discussion:https://postgr.es/m/22676.1494557205@sss.pgh.pa.us
1 parent2df5d46 commitd99d58c

File tree

7 files changed

+95
-3
lines changed

7 files changed

+95
-3
lines changed

‎doc/src/sgml/func.sgml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16680,6 +16680,12 @@ SELECT relname FROM pg_class WHERE pg_table_is_visible(oid);
1668016680
<entry><type>boolean</type></entry>
1668116681
<entry>is operator family visible in search path</entry>
1668216682
</row>
16683+
<row>
16684+
<entry><literal><function>pg_statistic_ext_is_visible(<parameter>stat_oid</parameter>)</function></literal>
16685+
</entry>
16686+
<entry><type>boolean</type></entry>
16687+
<entry>is statistics object visible in search path</entry>
16688+
</row>
1668316689
<row>
1668416690
<entry><literal><function>pg_table_is_visible(<parameter>table_oid</parameter>)</function></literal>
1668516691
</entry>
@@ -16738,6 +16744,9 @@ SELECT relname FROM pg_class WHERE pg_table_is_visible(oid);
1673816744
<indexterm>
1673916745
<primary>pg_opfamily_is_visible</primary>
1674016746
</indexterm>
16747+
<indexterm>
16748+
<primary>pg_statistic_ext_is_visible</primary>
16749+
</indexterm>
1674116750
<indexterm>
1674216751
<primary>pg_table_is_visible</primary>
1674316752
</indexterm>

‎src/backend/catalog/namespace.c

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include"catalog/pg_operator.h"
3535
#include"catalog/pg_opfamily.h"
3636
#include"catalog/pg_proc.h"
37+
#include"catalog/pg_statistic_ext.h"
3738
#include"catalog/pg_ts_config.h"
3839
#include"catalog/pg_ts_dict.h"
3940
#include"catalog/pg_ts_parser.h"
@@ -2141,6 +2142,72 @@ get_statistics_oid(List *names, bool missing_ok)
21412142
returnstats_oid;
21422143
}
21432144

2145+
/*
2146+
* StatisticsObjIsVisible
2147+
*Determine whether a statistics object (identified by OID) is visible in
2148+
*the current search path. Visible means "would be found by searching
2149+
*for the unqualified statistics object name".
2150+
*/
2151+
bool
2152+
StatisticsObjIsVisible(Oidrelid)
2153+
{
2154+
HeapTuplestxtup;
2155+
Form_pg_statistic_extstxform;
2156+
Oidstxnamespace;
2157+
boolvisible;
2158+
2159+
stxtup=SearchSysCache1(STATEXTOID,ObjectIdGetDatum(relid));
2160+
if (!HeapTupleIsValid(stxtup))
2161+
elog(ERROR,"cache lookup failed for statistics object %u",relid);
2162+
stxform= (Form_pg_statistic_ext)GETSTRUCT(stxtup);
2163+
2164+
recomputeNamespacePath();
2165+
2166+
/*
2167+
* Quick check: if it ain't in the path at all, it ain't visible. Items in
2168+
* the system namespace are surely in the path and so we needn't even do
2169+
* list_member_oid() for them.
2170+
*/
2171+
stxnamespace=stxform->stxnamespace;
2172+
if (stxnamespace!=PG_CATALOG_NAMESPACE&&
2173+
!list_member_oid(activeSearchPath,stxnamespace))
2174+
visible= false;
2175+
else
2176+
{
2177+
/*
2178+
* If it is in the path, it might still not be visible; it could be
2179+
* hidden by another statistics object of the same name earlier in the
2180+
* path. So we must do a slow check for conflicting objects.
2181+
*/
2182+
char*stxname=NameStr(stxform->stxname);
2183+
ListCell*l;
2184+
2185+
visible= false;
2186+
foreach(l,activeSearchPath)
2187+
{
2188+
OidnamespaceId=lfirst_oid(l);
2189+
2190+
if (namespaceId==stxnamespace)
2191+
{
2192+
/* Found it first in path */
2193+
visible= true;
2194+
break;
2195+
}
2196+
if (SearchSysCacheExists2(STATEXTNAMENSP,
2197+
PointerGetDatum(stxname),
2198+
ObjectIdGetDatum(namespaceId)))
2199+
{
2200+
/* Found something else first in path */
2201+
break;
2202+
}
2203+
}
2204+
}
2205+
2206+
ReleaseSysCache(stxtup);
2207+
2208+
returnvisible;
2209+
}
2210+
21442211
/*
21452212
* get_ts_parser_oid - find a TS parser by possibly qualified name
21462213
*
@@ -4235,6 +4302,17 @@ pg_conversion_is_visible(PG_FUNCTION_ARGS)
42354302
PG_RETURN_BOOL(ConversionIsVisible(oid));
42364303
}
42374304

4305+
Datum
4306+
pg_statistic_ext_is_visible(PG_FUNCTION_ARGS)
4307+
{
4308+
Oidoid=PG_GETARG_OID(0);
4309+
4310+
if (!SearchSysCacheExists1(STATEXTOID,ObjectIdGetDatum(oid)))
4311+
PG_RETURN_NULL();
4312+
4313+
PG_RETURN_BOOL(StatisticsObjIsVisible(oid));
4314+
}
4315+
42384316
Datum
42394317
pg_ts_parser_is_visible(PG_FUNCTION_ARGS)
42404318
{

‎src/backend/utils/cache/lsyscache.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include"catalog/pg_proc.h"
3333
#include"catalog/pg_range.h"
3434
#include"catalog/pg_statistic.h"
35+
#include"catalog/pg_statistic_ext.h"
3536
#include"catalog/pg_transform.h"
3637
#include"catalog/pg_type.h"
3738
#include"miscadmin.h"

‎src/bin/psql/tab-complete.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ static const SchemaQuery Query_for_list_of_statistics = {
622622
/* selcondition */
623623
NULL,
624624
/* viscondition */
625-
NULL,
625+
"pg_catalog.pg_statistic_ext_is_visible(s.oid)",
626626
/* namespace */
627627
"s.stxnamespace",
628628
/* result */

‎src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO201705121
56+
#defineCATALOG_VERSION_NO201705122
5757

5858
#endif

‎src/include/catalog/namespace.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ extern bool CollationIsVisible(Oid collid);
9292
externOidConversionGetConid(constchar*conname);
9393
externboolConversionIsVisible(Oidconid);
9494

95+
externOidget_statistics_oid(List*names,boolmissing_ok);
96+
externboolStatisticsObjIsVisible(Oidstxid);
97+
9598
externOidget_ts_parser_oid(List*names,boolmissing_ok);
9699
externboolTSParserIsVisible(OidprsId);
97100

@@ -141,7 +144,6 @@ extern Oidget_collation_oid(List *collname, bool missing_ok);
141144
externOidget_conversion_oid(List*conname,boolmissing_ok);
142145
externOidFindDefaultConversionProc(int32for_encoding,int32to_encoding);
143146

144-
externOidget_statistics_oid(List*names,boolmissing_ok);
145147

146148
/* initialization & transaction cleanup code */
147149
externvoidInitializeSearchPath(void);

‎src/include/catalog/pg_proc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3181,6 +3181,8 @@ DATA(insert OID = 3829 ( pg_opfamily_is_visiblePGNSP PGUID 12 10 0 0 0 f f f f
31813181
DESCR("is opfamily visible in search path?");
31823182
DATA(insert OID = 2093 ( pg_conversion_is_visiblePGNSP PGUID 12 10 0 0 0 f f f f t f s s 1 0 16 "26" _null_ _null_ _null_ _null_ _null_ pg_conversion_is_visible _null_ _null_ _null_ ));
31833183
DESCR("is conversion visible in search path?");
3184+
DATA(insert OID = 3403 ( pg_statistic_ext_is_visiblePGNSP PGUID 12 10 0 0 0 f f f f t f s s 1 0 16 "26" _null_ _null_ _null_ _null_ _null_ pg_statistic_ext_is_visible _null_ _null_ _null_ ));
3185+
DESCR("is statistics object visible in search path?");
31843186
DATA(insert OID = 3756 ( pg_ts_parser_is_visiblePGNSP PGUID 12 10 0 0 0 f f f f t f s s 1 0 16 "26" _null_ _null_ _null_ _null_ _null_ pg_ts_parser_is_visible _null_ _null_ _null_ ));
31853187
DESCR("is text search parser visible in search path?");
31863188
DATA(insert OID = 3757 ( pg_ts_dict_is_visiblePGNSP PGUID 12 10 0 0 0 f f f f t f s s 1 0 16 "26" _null_ _null_ _null_ _null_ _null_ pg_ts_dict_is_visible _null_ _null_ _null_ ));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp