Skip to content

Commit

Permalink
[#22364] YSQL: Enable CREATE/DROP ACCESS METHOD grammar
Browse files Browse the repository at this point in the history
Summary:
This diff enables the grammar for CREATE/DROP ACCESS METHOD.
Along with standard grammar enablement in `gram.y`. A test was added by adjusting postgres's `create_am.sql`. This test was modified to operate on a non-YB temporary table to allow testing adding a gist index ACCESS METHOD.

Upon manual testing, the `bloom` extension can now be created and bloom indexes can be created on temporary tables after this change.

The tables `slow_emp4000` and `fast_emp4000` in `yb_pg_create_misc.sql` were previously created but empty. This change imports its population for the purposes of `yb_pg_create_am.sql`.
Jira: DB-11266

Test Plan: ./yb_build.sh --java-test 'org.yb.pgsql.TestPgRegressMisc'

Reviewers: jason

Reviewed By: jason

Subscribers: yql

Differential Revision: https://phorge.dev.yugabyte.com/D34976
  • Loading branch information
tanujnay112 committed May 14, 2024
1 parent 12b6c74 commit c6291aa
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/postgres/src/backend/parser/gram.y
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,7 @@ stmt :
| CommentStmt
| ConstraintsSetStmt
| CopyStmt
| CreateAmStmt
| CreateCastStmt
| CreateDomainStmt
| CreateEventTrigStmt
Expand Down Expand Up @@ -1018,7 +1019,6 @@ stmt :
| AlterSubscriptionStmt { parser_ybc_not_support(@1, "This statement"); }
| AlterTSDictionaryStmt { parser_ybc_not_support(@1, "This statement"); }
| ClusterStmt { parser_ybc_not_support(@1, "This statement"); }
| CreateAmStmt { parser_ybc_not_support(@1, "This statement"); }
| CreateAssertStmt { parser_ybc_not_support(@1, "This statement"); }
| CreateConversionStmt { parser_ybc_not_support(@1, "This statement"); }
| CreateSubscriptionStmt { parser_ybc_not_support(@1, "This statement"); }
Expand Down Expand Up @@ -5855,7 +5855,6 @@ row_security_cmd:

CreateAmStmt: CREATE ACCESS METHOD name TYPE_P INDEX HANDLER handler_name
{
parser_ybc_not_support(@1, "CREATE ACCESS METHOD");
CreateAmStmt *n = makeNode(CreateAmStmt);
n->amname = $4;
n->handler_name = $8;
Expand Down Expand Up @@ -6927,7 +6926,10 @@ drop_type_any_name:

/* object types taking name_list */
drop_type_name:
ACCESS METHOD { parser_ybc_not_support(@1, "DROP ACCESS METHOD"); $$ = OBJECT_ACCESS_METHOD; }
ACCESS METHOD
{
$$ = OBJECT_ACCESS_METHOD;
}
| EVENT TRIGGER
{
$$ = OBJECT_EVENT_TRIGGER;
Expand Down
106 changes: 106 additions & 0 deletions src/postgres/src/test/regress/expected/yb_pg_create_am.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
--
-- Create access method tests
--
-- Make gist2 over gisthandler. In fact, it would be a synonym to gist.
CREATE ACCESS METHOD gist2 TYPE INDEX HANDLER gisthandler;
CREATE INDEX grect2ind2 ON fast_emp4000 USING gist2 (home_base); -- YB: Should fail because gist is unsupported on YB tables
ERROR: index method "gist2" not supported yet
HINT: See https://github.com/yugabyte/yugabyte-db/issues/1337. React with thumbs up to raise its priority
CREATE TEMP TABLE fast_emp4000 AS SELECT * FROM fast_emp4000; -- YB: workaround using temp table
-- Try to create gist2 index on fast_emp4000: fail because opclass doesn't exist
CREATE INDEX grect2ind2 ON fast_emp4000 USING gist2 (home_base);
ERROR: data type box has no default operator class for access method "gist2"
HINT: You must specify an operator class for the index or define a default operator class for the data type.
-- Make operator class for boxes using gist2
CREATE OPERATOR CLASS box_ops DEFAULT
FOR TYPE box USING gist2 AS
OPERATOR 1 <<,
OPERATOR 2 &<,
OPERATOR 3 &&,
OPERATOR 4 &>,
OPERATOR 5 >>,
OPERATOR 6 ~=,
OPERATOR 7 @>,
OPERATOR 8 <@,
OPERATOR 9 &<|,
OPERATOR 10 <<|,
OPERATOR 11 |>>,
OPERATOR 12 |&>,
OPERATOR 13 ~,
OPERATOR 14 @,
FUNCTION 1 gist_box_consistent(internal, box, smallint, oid, internal),
FUNCTION 2 gist_box_union(internal, internal),
-- don't need compress, decompress, or fetch functions
FUNCTION 5 gist_box_penalty(internal, internal, internal),
FUNCTION 6 gist_box_picksplit(internal, internal),
FUNCTION 7 gist_box_same(box, box, internal);
-- Create gist2 index on fast_emp4000
CREATE INDEX grect2ind2 ON fast_emp4000 USING gist2 (home_base);
-- Now check the results from plain indexscan; temporarily drop existing
-- index grect2ind to ensure it doesn't capture the plan.
-- BEGIN; -- YB: Commented out because DDL in txn is unsupported
DROP INDEX grect2ind; -- YB: fails because CREATE INDEX grect2ind is not yet ported in yb_pg_create_index
ERROR: index "grect2ind" does not exist
SET enable_seqscan = OFF;
SET enable_indexscan = ON;
SET enable_bitmapscan = OFF;
EXPLAIN (COSTS OFF)
SELECT * FROM fast_emp4000
WHERE home_base @ '(200,200),(2000,1000)'::box
ORDER BY (home_base[0])[0];
QUERY PLAN
----------------------------------------------------------------
Sort
Sort Key: ((home_base[0])[0])
-> Index Only Scan using grect2ind2 on fast_emp4000
Index Cond: (home_base @ '(2000,1000),(200,200)'::box)
(4 rows)

SELECT * FROM fast_emp4000
WHERE home_base @ '(200,200),(2000,1000)'::box
ORDER BY (home_base[0])[0];
home_base
-----------------------
(337,455),(240,359)
(1444,403),(1346,344)
(2 rows)

EXPLAIN (COSTS OFF)
SELECT count(*) FROM fast_emp4000 WHERE home_base && '(1000,1000,0,0)'::box;
QUERY PLAN
-------------------------------------------------------------
Aggregate
-> Index Only Scan using grect2ind2 on fast_emp4000
Index Cond: (home_base && '(1000,1000),(0,0)'::box)
(3 rows)

SELECT count(*) FROM fast_emp4000 WHERE home_base && '(1000,1000,0,0)'::box;
count
-------
2
(1 row)

EXPLAIN (COSTS OFF)
SELECT count(*) FROM fast_emp4000 WHERE home_base IS NULL;
QUERY PLAN
--------------------------------------------------------
Aggregate
-> Index Only Scan using grect2ind2 on fast_emp4000
Index Cond: (home_base IS NULL)
(3 rows)

SELECT count(*) FROM fast_emp4000 WHERE home_base IS NULL;
count
-------
278
(1 row)

-- ROLLBACK; -- YB: We don't need to rollback as we didn't begin a transaction.
-- Try to drop access method: fail because of dependent objects
DROP ACCESS METHOD gist2;
ERROR: cannot drop access method gist2 because other objects depend on it
DETAIL: index grect2ind2 depends on operator class box_ops for access method gist2
HINT: Use DROP ... CASCADE to drop the dependent objects too.
-- Drop access method cascade
DROP ACCESS METHOD gist2 CASCADE;
NOTICE: drop cascades to index grect2ind2
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
--
INSERT INTO tenk2 SELECT * FROM tenk1;
SELECT * INTO TABLE onek2 FROM onek;
INSERT INTO fast_emp4000 SELECT * FROM slow_emp4000;
2 changes: 2 additions & 0 deletions src/postgres/src/test/regress/input/yb_pg_copy.source
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ COPY onek FROM '@abs_builddir@/results/onek.data';

COPY tenk1 FROM '@abs_srcdir@/data/tenk.data';

COPY slow_emp4000 FROM '@abs_srcdir@/data/rect.data';

COPY person FROM '@abs_srcdir@/data/person.data';

COPY test_tsvector FROM '@abs_srcdir@/data/tsearch.data';
Expand Down
1 change: 1 addition & 0 deletions src/postgres/src/test/regress/output/yb_pg_copy.source
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ COPY onek TO '@abs_builddir@/results/onek.data';
DELETE FROM onek;
COPY onek FROM '@abs_builddir@/results/onek.data';
COPY tenk1 FROM '@abs_srcdir@/data/tenk.data';
COPY slow_emp4000 FROM '@abs_srcdir@/data/rect.data';
COPY person FROM '@abs_srcdir@/data/person.data';
COPY test_tsvector FROM '@abs_srcdir@/data/tsearch.data';
COPY testjsonb FROM '@abs_srcdir@/data/jsonb.data';
Expand Down
70 changes: 70 additions & 0 deletions src/postgres/src/test/regress/sql/yb_pg_create_am.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
--
-- Create access method tests
--

-- Make gist2 over gisthandler. In fact, it would be a synonym to gist.
CREATE ACCESS METHOD gist2 TYPE INDEX HANDLER gisthandler;

CREATE INDEX grect2ind2 ON fast_emp4000 USING gist2 (home_base); -- YB: Should fail because gist is unsupported on YB tables
CREATE TEMP TABLE fast_emp4000 AS SELECT * FROM fast_emp4000; -- YB: workaround using temp table
-- Try to create gist2 index on fast_emp4000: fail because opclass doesn't exist
CREATE INDEX grect2ind2 ON fast_emp4000 USING gist2 (home_base);

-- Make operator class for boxes using gist2
CREATE OPERATOR CLASS box_ops DEFAULT
FOR TYPE box USING gist2 AS
OPERATOR 1 <<,
OPERATOR 2 &<,
OPERATOR 3 &&,
OPERATOR 4 &>,
OPERATOR 5 >>,
OPERATOR 6 ~=,
OPERATOR 7 @>,
OPERATOR 8 <@,
OPERATOR 9 &<|,
OPERATOR 10 <<|,
OPERATOR 11 |>>,
OPERATOR 12 |&>,
OPERATOR 13 ~,
OPERATOR 14 @,
FUNCTION 1 gist_box_consistent(internal, box, smallint, oid, internal),
FUNCTION 2 gist_box_union(internal, internal),
-- don't need compress, decompress, or fetch functions
FUNCTION 5 gist_box_penalty(internal, internal, internal),
FUNCTION 6 gist_box_picksplit(internal, internal),
FUNCTION 7 gist_box_same(box, box, internal);

-- Create gist2 index on fast_emp4000
CREATE INDEX grect2ind2 ON fast_emp4000 USING gist2 (home_base);

-- Now check the results from plain indexscan; temporarily drop existing
-- index grect2ind to ensure it doesn't capture the plan.
-- BEGIN; -- YB: Commented out because DDL in txn is unsupported
DROP INDEX grect2ind; -- YB: fails because CREATE INDEX grect2ind is not yet ported in yb_pg_create_index
SET enable_seqscan = OFF;
SET enable_indexscan = ON;
SET enable_bitmapscan = OFF;

EXPLAIN (COSTS OFF)
SELECT * FROM fast_emp4000
WHERE home_base @ '(200,200),(2000,1000)'::box
ORDER BY (home_base[0])[0];
SELECT * FROM fast_emp4000
WHERE home_base @ '(200,200),(2000,1000)'::box
ORDER BY (home_base[0])[0];

EXPLAIN (COSTS OFF)
SELECT count(*) FROM fast_emp4000 WHERE home_base && '(1000,1000,0,0)'::box;
SELECT count(*) FROM fast_emp4000 WHERE home_base && '(1000,1000,0,0)'::box;

EXPLAIN (COSTS OFF)
SELECT count(*) FROM fast_emp4000 WHERE home_base IS NULL;
SELECT count(*) FROM fast_emp4000 WHERE home_base IS NULL;

-- ROLLBACK; -- YB: We don't need to rollback as we didn't begin a transaction.

-- Try to drop access method: fail because of dependent objects
DROP ACCESS METHOD gist2;

-- Drop access method cascade
DROP ACCESS METHOD gist2 CASCADE;
2 changes: 2 additions & 0 deletions src/postgres/src/test/regress/sql/yb_pg_create_misc.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@
INSERT INTO tenk2 SELECT * FROM tenk1;

SELECT * INTO TABLE onek2 FROM onek;

INSERT INTO fast_emp4000 SELECT * FROM slow_emp4000;
3 changes: 2 additions & 1 deletion src/postgres/src/test/regress/yb_pg_misc_serial_schedule
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ test: yb_pg_create_table

test: yb_pg_create_function_2

# Dependency for yb_pg_with
# Dependency for yb_pg_with and yb_pg_create_am
test: yb_pg_copy

test: yb_pg_create_misc
test: yb_pg_create_operator
test: yb_pg_create_index
test: yb_pg_create_am
test: yb_pg_errors
test: yb_pg_with

0 comments on commit c6291aa

Please sign in to comment.