Skip to content

Commit

Permalink
[YSQL][#2217] Enable ANALYZE, VACUUM in grammar
Browse files Browse the repository at this point in the history
Summary:
Enable the `ANALYZE` and `VACUUM` statements as beta features in
`gram.y`.  Disable `ANALYZE` for Yugabyte relations, and disable
`VACUUM` when Yugabyte is enabled.

Test Plan:
* Jenkins
* `TestPgMisc` java test
* `yb_pg_plpgsql` regress test of `TestPgRegressBetaFeatures` java test

Reviewers: neha, mihnea

Reviewed By: mihnea

Subscribers: yql

Differential Revision: https://phabricator.dev.yugabyte.com/D7160
  • Loading branch information
Jason Kim committed Sep 6, 2019
1 parent c1d63c6 commit c030c7a
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 32 deletions.
27 changes: 23 additions & 4 deletions java/yb-pgsql/src/test/java/org/yb/pgsql/TestPgMisc.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.postgresql.util.PSQLException;
import org.postgresql.util.PSQLWarning;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yb.util.YBTestRunnerNonTsanOnly;
Expand Down Expand Up @@ -106,11 +107,29 @@ public void testSequenceCreationInTemplate() throws Exception {
}

@Test
public void testFeatureRestrictionInTemplate() throws Exception {
try {
executeQueryInTemplate("VACUUM;");
fail("Restricted feature executed in template");
public void testVacuum() throws Exception {
try (Statement statement = connection.createStatement()) {
statement.execute("VACUUM;");
if (statement.getWarnings() != null) {
throw statement.getWarnings();
}
fail("Vacuum executed without warnings");
} catch(PSQLWarning w) {
}
}

@Test
public void testTemporaryTableAnalyze() throws Exception {
try (Statement statement = connection.createStatement()) {
statement.execute("CREATE TEMP TABLE test_table(a int);");
statement.execute("ANALYZE test_table;");
if (statement.getWarnings() != null) {
throw statement.getWarnings();
}
} catch(PSQLException e) {
fail("Analyze executed with exception");
} catch(PSQLWarning w) {
fail("Analyze executed with warning");
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/postgres/src/backend/commands/analyze.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,16 @@ do_analyze_rel(Relation onerel, int options, VacuumParams *params,
int save_sec_context;
int save_nestlevel;

/*
* ANALYZE not supported for Yugabyte relations.
*/
if (IsYBRelation(onerel))
{
ereport(WARNING,
(errmsg("analyzing non-temporary tables will be ignored")));
return;
}

if (inh)
ereport(elevel,
(errmsg("analyzing \"%s.%s\" inheritance tree",
Expand Down
16 changes: 10 additions & 6 deletions src/postgres/src/backend/commands/vacuum.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@ ExecVacuum(VacuumStmt *vacstmt, bool isTopLevel)
{
VacuumParams params;

/* No need for vacuming in YB mode. */
if (IsYugaByteEnabled())
{
return;
}

/* sanity checks on options */
Assert(vacstmt->options & (VACOPT_VACUUM | VACOPT_ANALYZE));
Assert((vacstmt->options & VACOPT_VACUUM) ||
Expand Down Expand Up @@ -179,6 +173,16 @@ vacuum(int options, List *relations, VacuumParams *params,
volatile bool in_outer_xact,
use_own_xacts;

/*
* VACUUM currently not supported for Yugabyte.
*/
if (options & VACOPT_VACUUM)
{
ereport(WARNING,
(errmsg("VACUUM will be ignored")));
return;
}

Assert(params != NULL);

stmttype = (options & VACOPT_VACUUM) ? "VACUUM" : "ANALYZE";
Expand Down
8 changes: 2 additions & 6 deletions src/postgres/src/backend/parser/gram.y
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,7 @@ stmt :
| ViewStmt

/* BETA features */
| AnalyzeStmt { parser_ybc_beta_feature(@1, "analyze"); }
| CreateFunctionStmt { parser_ybc_beta_feature(@1, "function"); }
| DoStmt { parser_ybc_beta_feature(@1, "function"); }
| RemoveFuncStmt { parser_ybc_beta_feature(@1, "function"); }
Expand All @@ -925,6 +926,7 @@ stmt :
| GrantRoleStmt { parser_ybc_beta_feature(@1, "roles"); }
| ReassignOwnedStmt { parser_ybc_beta_feature(@1, "roles"); }
| RevokeRoleStmt { parser_ybc_beta_feature(@1, "roles"); }
| VacuumStmt { parser_ybc_beta_feature(@1, "vacuum"); }

/* Not supported in template0/template1 statements */
| CreateAsStmt { parser_ybc_not_support_in_templates(@1, "This statement"); }
Expand Down Expand Up @@ -953,7 +955,6 @@ stmt :
| AlterTSConfigurationStmt { parser_ybc_not_support(@1, "This statement"); }
| AlterTSDictionaryStmt { parser_ybc_not_support(@1, "This statement"); }
| AlterUserMappingStmt { parser_ybc_not_support(@1, "This statement"); }
| AnalyzeStmt { parser_ybc_not_support(@1, "This statement"); }
| CheckPointStmt { parser_ybc_not_support(@1, "This statement"); }
| ClosePortalStmt { parser_ybc_not_support(@1, "This statement"); }
| ClusterStmt { parser_ybc_not_support(@1, "This statement"); }
Expand Down Expand Up @@ -999,7 +1000,6 @@ stmt :
| RuleStmt { parser_ybc_not_support(@1, "This statement"); }
| SecLabelStmt { parser_ybc_not_support(@1, "This statement"); }
| UnlistenStmt { parser_ybc_not_support(@1, "This statement"); }
| VacuumStmt { parser_ybc_not_support(@1, "This statement"); }
;

/*****************************************************************************
Expand Down Expand Up @@ -11271,7 +11271,6 @@ cluster_index_specification:

VacuumStmt: VACUUM opt_full opt_freeze opt_verbose opt_analyze opt_vacuum_relation_list
{
parser_ybc_not_support(@1, "VACUUM");
VacuumStmt *n = makeNode(VacuumStmt);
n->options = VACOPT_VACUUM;
if ($2)
Expand All @@ -11287,7 +11286,6 @@ VacuumStmt: VACUUM opt_full opt_freeze opt_verbose opt_analyze opt_vacuum_relati
}
| VACUUM '(' vacuum_option_list ')' opt_vacuum_relation_list
{
parser_ybc_not_support(@1, "VACUUM");
VacuumStmt *n = makeNode(VacuumStmt);
n->options = VACOPT_VACUUM | $3;
n->rels = $5;
Expand Down Expand Up @@ -11319,7 +11317,6 @@ vacuum_option_elem:

AnalyzeStmt: analyze_keyword opt_verbose opt_vacuum_relation_list
{
parser_ybc_not_support(@1, "ANALYZE");
VacuumStmt *n = makeNode(VacuumStmt);
n->options = VACOPT_ANALYZE;
if ($2)
Expand All @@ -11329,7 +11326,6 @@ AnalyzeStmt: analyze_keyword opt_verbose opt_vacuum_relation_list
}
| analyze_keyword '(' analyze_option_list ')' opt_vacuum_relation_list
{
parser_ybc_not_support(@1, "ANALYZE");
VacuumStmt *n = makeNode(VacuumStmt);
n->options = VACOPT_ANALYZE | $3;
n->rels = $5;
Expand Down
20 changes: 4 additions & 16 deletions src/postgres/src/test/regress/expected/yb_pg_plpgsql.out
Original file line number Diff line number Diff line change
Expand Up @@ -5328,34 +5328,22 @@ HINT: See https://github.com/YugaByte/yugabyte-db/issues/1668. Click '+' on the
INSERT INTO transition_table_level1 (level1_no)
SELECT generate_series(1,200);
ANALYZE transition_table_level1;
ERROR: ANALYZE not supported yet
LINE 1: ANALYZE transition_table_level1;
^
HINT: Please report the issue on https://github.com/YugaByte/yugabyte-db/issues
WARNING: analyzing non-temporary tables will be ignored
INSERT INTO transition_table_level2 (level2_no, parent_no)
SELECT level2_no, level2_no / 50 + 1 AS parent_no
FROM generate_series(1,9999) level2_no;
ANALYZE transition_table_level2;
ERROR: ANALYZE not supported yet
LINE 1: ANALYZE transition_table_level2;
^
HINT: Please report the issue on https://github.com/YugaByte/yugabyte-db/issues
WARNING: analyzing non-temporary tables will be ignored
INSERT INTO transition_table_status (level, node_no, status)
SELECT 1, level1_no, 0 FROM transition_table_level1;
INSERT INTO transition_table_status (level, node_no, status)
SELECT 2, level2_no, 0 FROM transition_table_level2;
ANALYZE transition_table_status;
ERROR: ANALYZE not supported yet
LINE 1: ANALYZE transition_table_status;
^
HINT: Please report the issue on https://github.com/YugaByte/yugabyte-db/issues
WARNING: analyzing non-temporary tables will be ignored
INSERT INTO transition_table_level1(level1_no)
SELECT generate_series(201,1000);
ANALYZE transition_table_level1;
ERROR: ANALYZE not supported yet
LINE 1: ANALYZE transition_table_level1;
^
HINT: Please report the issue on https://github.com/YugaByte/yugabyte-db/issues
WARNING: analyzing non-temporary tables will be ignored
-- behave reasonably if someone tries to modify a transition table
CREATE FUNCTION transition_table_level2_bad_usage_func()
RETURNS TRIGGER
Expand Down

0 comments on commit c030c7a

Please sign in to comment.