Skip to content

Commit 92a30a7

Browse files
committed
Fix broken dependency-mongering for index operator classes/families.
For a long time, opclasscmds.c explained that "we do not create a dependency link to the AM [for an opclass or opfamily], because we don't currently support DROP ACCESS METHOD". Commit 473b932 invented DROP ACCESS METHOD, but it batted only 1 for 2 on adding the dependency links, and 0 for 2 on updating the comments about the topic. In passing, undo the same commit's entirely inappropriate decision to blow away an existing index as a side-effect of create_am.sql.
1 parent c8cb745 commit 92a30a7

File tree

4 files changed

+34
-45
lines changed

4 files changed

+34
-45
lines changed

src/backend/commands/opclasscmds.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -285,14 +285,18 @@ CreateOpFamily(char *amname, char *opfname, Oid namespaceoid, Oid amoid)
285285
heap_freetuple(tup);
286286

287287
/*
288-
* Create dependencies for the opfamily proper. Note: we do not create a
289-
* dependency link to the AM, because we don't currently support DROP
290-
* ACCESS METHOD.
288+
* Create dependencies for the opfamily proper.
291289
*/
292290
myself.classId = OperatorFamilyRelationId;
293291
myself.objectId = opfamilyoid;
294292
myself.objectSubId = 0;
295293

294+
/* dependency on access method */
295+
referenced.classId = AccessMethodRelationId;
296+
referenced.objectId = amoid;
297+
referenced.objectSubId = 0;
298+
recordDependencyOn(&myself, &referenced, DEPENDENCY_AUTO);
299+
296300
/* dependency on namespace */
297301
referenced.classId = NamespaceRelationId;
298302
referenced.objectId = namespaceoid;
@@ -670,20 +674,13 @@ DefineOpClass(CreateOpClassStmt *stmt)
670674
EventTriggerCollectCreateOpClass(stmt, opclassoid, operators, procedures);
671675

672676
/*
673-
* Create dependencies for the opclass proper. Note: we do not create a
674-
* dependency link to the AM, because we don't currently support DROP
675-
* ACCESS METHOD.
677+
* Create dependencies for the opclass proper. Note: we do not need a
678+
* dependency link to the AM, because that exists through the opfamily.
676679
*/
677680
myself.classId = OperatorClassRelationId;
678681
myself.objectId = opclassoid;
679682
myself.objectSubId = 0;
680683

681-
/* dependency on access method */
682-
referenced.classId = AccessMethodRelationId;
683-
referenced.objectId = amoid;
684-
referenced.objectSubId = 0;
685-
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
686-
687684
/* dependency on namespace */
688685
referenced.classId = NamespaceRelationId;
689686
referenced.objectId = namespaceoid;

src/test/regress/expected/create_am.out

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
--
44
-- Make gist2 over gisthandler. In fact, it would be a synonym to gist.
55
CREATE ACCESS METHOD gist2 TYPE INDEX HANDLER gisthandler;
6-
-- Drop old index on fast_emp4000
7-
DROP INDEX grect2ind;
86
-- Try to create gist2 index on fast_emp4000: fail because opclass doesn't exist
9-
CREATE INDEX grect2ind ON fast_emp4000 USING gist2 (home_base);
7+
CREATE INDEX grect2ind2 ON fast_emp4000 USING gist2 (home_base);
108
ERROR: data type box has no default operator class for access method "gist2"
119
HINT: You must specify an operator class for the index or define a default operator class for the data type.
1210
-- Make operator class for boxes using gist2
@@ -35,8 +33,11 @@ CREATE OPERATOR CLASS box_ops DEFAULT
3533
FUNCTION 7 gist_box_same(box, box, internal),
3634
FUNCTION 9 gist_box_fetch(internal);
3735
-- Create gist2 index on fast_emp4000
38-
CREATE INDEX grect2ind ON fast_emp4000 USING gist2 (home_base);
39-
-- Now check the results from plain indexscan
36+
CREATE INDEX grect2ind2 ON fast_emp4000 USING gist2 (home_base);
37+
-- Now check the results from plain indexscan; temporarily drop existing
38+
-- index grect2ind to ensure it doesn't capture the plan
39+
BEGIN;
40+
DROP INDEX grect2ind;
4041
SET enable_seqscan = OFF;
4142
SET enable_indexscan = ON;
4243
SET enable_bitmapscan = OFF;
@@ -48,7 +49,7 @@ SELECT * FROM fast_emp4000
4849
----------------------------------------------------------------
4950
Sort
5051
Sort Key: ((home_base[0])[0])
51-
-> Index Only Scan using grect2ind on fast_emp4000
52+
-> Index Only Scan using grect2ind2 on fast_emp4000
5253
Index Cond: (home_base @ '(2000,1000),(200,200)'::box)
5354
(4 rows)
5455

@@ -66,7 +67,7 @@ SELECT count(*) FROM fast_emp4000 WHERE home_base && '(1000,1000,0,0)'::box;
6667
QUERY PLAN
6768
-------------------------------------------------------------
6869
Aggregate
69-
-> Index Only Scan using grect2ind on fast_emp4000
70+
-> Index Only Scan using grect2ind2 on fast_emp4000
7071
Index Cond: (home_base && '(1000,1000),(0,0)'::box)
7172
(3 rows)
7273

@@ -78,10 +79,10 @@ SELECT count(*) FROM fast_emp4000 WHERE home_base && '(1000,1000,0,0)'::box;
7879

7980
EXPLAIN (COSTS OFF)
8081
SELECT count(*) FROM fast_emp4000 WHERE home_base IS NULL;
81-
QUERY PLAN
82-
-------------------------------------------------------
82+
QUERY PLAN
83+
--------------------------------------------------------
8384
Aggregate
84-
-> Index Only Scan using grect2ind on fast_emp4000
85+
-> Index Only Scan using grect2ind2 on fast_emp4000
8586
Index Cond: (home_base IS NULL)
8687
(3 rows)
8788

@@ -91,18 +92,12 @@ SELECT count(*) FROM fast_emp4000 WHERE home_base IS NULL;
9192
278
9293
(1 row)
9394

94-
-- Try to drop access method: fail because of depending objects
95+
ROLLBACK;
96+
-- Try to drop access method: fail because of dependent objects
9597
DROP ACCESS METHOD gist2;
9698
ERROR: cannot drop access method gist2 because other objects depend on it
97-
DETAIL: operator class box_ops for access method gist2 depends on access method gist2
98-
index grect2ind depends on operator class box_ops for access method gist2
99+
DETAIL: index grect2ind2 depends on operator class box_ops for access method gist2
99100
HINT: Use DROP ... CASCADE to drop the dependent objects too.
100101
-- Drop access method cascade
101102
DROP ACCESS METHOD gist2 CASCADE;
102-
NOTICE: drop cascades to 2 other objects
103-
DETAIL: drop cascades to operator class box_ops for access method gist2
104-
drop cascades to index grect2ind
105-
-- Reset optimizer options
106-
RESET enable_seqscan;
107-
RESET enable_indexscan;
108-
RESET enable_bitmapscan;
103+
NOTICE: drop cascades to index grect2ind2

src/test/regress/expected/sanity_check.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ e_star|f
4444
emp|f
4545
equipment_r|f
4646
f_star|f
47-
fast_emp4000|f
47+
fast_emp4000|t
4848
float4_tbl|f
4949
float8_tbl|f
5050
func_index_heap|t

src/test/regress/sql/create_am.sql

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@
55
-- Make gist2 over gisthandler. In fact, it would be a synonym to gist.
66
CREATE ACCESS METHOD gist2 TYPE INDEX HANDLER gisthandler;
77

8-
-- Drop old index on fast_emp4000
9-
DROP INDEX grect2ind;
10-
118
-- Try to create gist2 index on fast_emp4000: fail because opclass doesn't exist
12-
CREATE INDEX grect2ind ON fast_emp4000 USING gist2 (home_base);
9+
CREATE INDEX grect2ind2 ON fast_emp4000 USING gist2 (home_base);
1310

1411
-- Make operator class for boxes using gist2
1512
CREATE OPERATOR CLASS box_ops DEFAULT
@@ -38,9 +35,12 @@ CREATE OPERATOR CLASS box_ops DEFAULT
3835
FUNCTION 9 gist_box_fetch(internal);
3936

4037
-- Create gist2 index on fast_emp4000
41-
CREATE INDEX grect2ind ON fast_emp4000 USING gist2 (home_base);
38+
CREATE INDEX grect2ind2 ON fast_emp4000 USING gist2 (home_base);
4239

43-
-- Now check the results from plain indexscan
40+
-- Now check the results from plain indexscan; temporarily drop existing
41+
-- index grect2ind to ensure it doesn't capture the plan
42+
BEGIN;
43+
DROP INDEX grect2ind;
4444
SET enable_seqscan = OFF;
4545
SET enable_indexscan = ON;
4646
SET enable_bitmapscan = OFF;
@@ -61,13 +61,10 @@ EXPLAIN (COSTS OFF)
6161
SELECT count(*) FROM fast_emp4000 WHERE home_base IS NULL;
6262
SELECT count(*) FROM fast_emp4000 WHERE home_base IS NULL;
6363

64-
-- Try to drop access method: fail because of depending objects
64+
ROLLBACK;
65+
66+
-- Try to drop access method: fail because of dependent objects
6567
DROP ACCESS METHOD gist2;
6668

6769
-- Drop access method cascade
6870
DROP ACCESS METHOD gist2 CASCADE;
69-
70-
-- Reset optimizer options
71-
RESET enable_seqscan;
72-
RESET enable_indexscan;
73-
RESET enable_bitmapscan;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy