Skip to content

Commit 53ea585

Browse files
BUG#28448258 - PREPARED STATEMENT FAILS FOR SET RESOURCE GROUP.
The SET RESOURCE GROUP doesn't support the prepared statment protocol mode. The patch adds prepared statement support for SET RESOURCE GROUP.
1 parent dad7cc3 commit 53ea585

File tree

6 files changed

+68
-6
lines changed

6 files changed

+68
-6
lines changed

mysql-test/include/resource_group_common.inc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,16 @@ SELECT func();
341341
SELECT COUNT(*) = 1 FROM performance_schema.threads WHERE RESOURCE_GROUP="Batch";
342342
DROP RESOURCE GROUP Batch FORCE;
343343
DROP FUNCTION func;
344+
345+
346+
#
347+
# BUG#28448258 - PREPARED STATEMENT FAILS FOR SET RESOURCE GROUP
348+
#
349+
CREATE RESOURCE GROUP test TYPE = USER VCPU=2-3;
350+
SET @rg_name='test';
351+
SET @cmd = CONCAT("SET RESOURCE GROUP ", @rg_name);
352+
SELECT @cmd;
353+
PREPARE stmt FROM @cmd;
354+
EXECUTE stmt;
355+
SELECT COUNT(*) = 1 FROM performance_schema.threads WHERE RESOURCE_GROUP="test";
356+
DROP RESOURCE GROUP test FORCE;

mysql-test/r/resource_group.result

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,15 @@ COUNT(*) = 1
262262
1
263263
DROP RESOURCE GROUP Batch FORCE;
264264
DROP FUNCTION func;
265+
CREATE RESOURCE GROUP test TYPE = USER VCPU=2-3;
266+
SET @rg_name='test';
267+
SET @cmd = CONCAT("SET RESOURCE GROUP ", @rg_name);
268+
SELECT @cmd;
269+
@cmd
270+
SET RESOURCE GROUP test
271+
PREPARE stmt FROM @cmd;
272+
EXECUTE stmt;
273+
SELECT COUNT(*) = 1 FROM performance_schema.threads WHERE RESOURCE_GROUP="test";
274+
COUNT(*) = 1
275+
1
276+
DROP RESOURCE GROUP test FORCE;

mysql-test/r/resource_group_thr_prio_unsupported.result

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,15 @@ COUNT(*) = 1
259259
1
260260
DROP RESOURCE GROUP Batch FORCE;
261261
DROP FUNCTION func;
262+
CREATE RESOURCE GROUP test TYPE = USER VCPU=2-3;
263+
SET @rg_name='test';
264+
SET @cmd = CONCAT("SET RESOURCE GROUP ", @rg_name);
265+
SELECT @cmd;
266+
@cmd
267+
SET RESOURCE GROUP test
268+
PREPARE stmt FROM @cmd;
269+
EXECUTE stmt;
270+
SELECT COUNT(*) = 1 FROM performance_schema.threads WHERE RESOURCE_GROUP="test";
271+
COUNT(*) = 1
272+
1
273+
DROP RESOURCE GROUP test FORCE;

sql/resourcegroups/resource_group_sql_cmd.cc

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -604,16 +604,29 @@ static inline bool check_and_apply_resource_grp(
604604
return false;
605605
}
606606

607-
bool resourcegroups::Sql_cmd_set_resource_group::execute(THD *thd) {
608-
DBUG_ENTER("resourcegroups::Sql_cmd_set_resource_group::execute");
607+
/**
608+
Check if user has sufficient privilege to exercise SET RESOURCE GROUP.
609609
610-
Security_context *sctx = thd->security_context();
610+
@param sctx Pointer to security context.
611+
612+
@return true if sufficient privilege exists for SET RESOURCE GROUP else false.
613+
*/
614+
615+
static bool check_resource_group_set_privilege(Security_context *sctx) {
611616
if (!(sctx->has_global_grant(STRING_WITH_LEN("RESOURCE_GROUP_ADMIN")).first ||
612617
sctx->has_global_grant(STRING_WITH_LEN("RESOURCE_GROUP_USER")).first)) {
613618
my_error(ER_SPECIFIC_ACCESS_DENIED_ERROR, MYF(0),
614619
"RESOURCE_GROUP_ADMIN OR RESOURCE_GROUP_USER");
615-
DBUG_RETURN(true);
620+
return true;
616621
}
622+
return false;
623+
}
624+
625+
bool resourcegroups::Sql_cmd_set_resource_group::execute(THD *thd) {
626+
DBUG_ENTER("resourcegroups::Sql_cmd_set_resource_group::execute");
627+
628+
Security_context *sctx = thd->security_context();
629+
if (check_resource_group_set_privilege(sctx)) DBUG_RETURN(true);
617630

618631
// Acquire exclusive lock on the resource group name to synchronize with hint.
619632
if (acquire_exclusive_mdl_for_resource_group(thd, m_name.str))
@@ -701,3 +714,13 @@ bool resourcegroups::Sql_cmd_set_resource_group::execute(THD *thd) {
701714
my_ok(thd);
702715
DBUG_RETURN(false);
703716
}
717+
718+
bool resourcegroups::Sql_cmd_set_resource_group::prepare(THD *thd) {
719+
DBUG_ENTER("Sql_cmd_set_resource_group::prepare");
720+
721+
if (Sql_cmd::prepare(thd)) DBUG_RETURN(true);
722+
723+
bool rc = check_resource_group_set_privilege(thd->security_context());
724+
725+
DBUG_RETURN(rc);
726+
}

sql/resourcegroups/resource_group_sql_cmd.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -130,7 +130,7 @@ class Sql_cmd_drop_resource_group : public Sql_cmd {
130130
Sql_cmd_set_resource_group represents SET RESOURCE GROUP statement.
131131
*/
132132

133-
class Sql_cmd_set_resource_group : public Sql_cmd {
133+
class Sql_cmd_set_resource_group final : public Sql_cmd {
134134
friend class ::PT_set_resource_group;
135135

136136
public:
@@ -143,6 +143,7 @@ class Sql_cmd_set_resource_group : public Sql_cmd {
143143
}
144144

145145
bool execute(THD *thd) override;
146+
bool prepare(THD *thd) override;
146147

147148
private:
148149
const LEX_CSTRING m_name;

sql/sql_prepare.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,7 @@ static bool check_prepared_statement(Prepared_statement *stmt) {
13151315
case SQLCOM_SHOW_FIELDS:
13161316
case SQLCOM_SHOW_KEYS:
13171317
case SQLCOM_CREATE_TABLE:
1318+
case SQLCOM_SET_RESOURCE_GROUP:
13181319
res = lex->m_sql_cmd->prepare(thd);
13191320
// @todo Temporary solution: Unprepare after preparation to preserve
13201321
// old behaviour

0 commit comments

Comments
 (0)