Details
-
Bug
-
Status: Closed (View Workflow)
-
Minor
-
Resolution: Fixed
-
5.5.41, 5.5.46, 5.5(EOL), 10.0(EOL), 10.1(EOL)
-
Tested on Windows 2012, CentOS6.7
Description
When creating a table with a constraint which references a table without explicitly naming the database the statement fails with the following error.
ERROR 1046 (3D000) at line ##@ No database selected.
|
The test statement used is as follows:
CREATE TABLE `kg_test1`.`person` |
(
|
`Id` INT(11) NOT NULL AUTO_INCREMENT, |
`Name` VARCHAR(50) NOT NULL, |
PRIMARY KEY (`Id`), |
CONSTRAINT `fk_person_group` FOREIGN KEY (`Id`) REFERENCES `group` (`Id`) |
) ENGINE=INNODB DEFAULT CHARSET=utf8; |
I'm using a local client to connect and run the test statement on MariaDB 5.5.41 - 46, on both Windows 2012 & CentOS 6.7....which all fail with the same error as above.
You can work around this by either adding a database name to the reference, (kg_test1.group) or adding database context (i.e. use <db-name>) when logging in via the client, but it does not have to be the same database the table is being created in.
This is a change in behaviour to MariaDB verisons prior to 5.5.41.
Attachments
Activity
Field | Original Value | New Value |
---|---|---|
Affects Version/s | 5.5 [ 15800 ] | |
Affects Version/s | 10.0 [ 16000 ] | |
Affects Version/s | 10.1 [ 16100 ] | |
Affects Version/s | 5.5.42 [ 18102 ] | |
Affects Version/s | 5.5.43 [ 18601 ] | |
Affects Version/s | 5.5.44 [ 19100 ] | |
Affects Version/s | 5.5.45 [ 19405 ] | |
Assignee | Jan Lindström [ jplindst ] |
Status | Open [ 1 ] | Confirmed [ 10101 ] |
Labels | upstream |
Description |
When creating a table with a constraint which references a table without explicitly naming the database the statement fails with the following error. ERROR 1046 (3D000) at line ##@ No database selected. The test statement used is as follows: CREATE TABLE `kg_test1`.`person` ( `Id` INT(11) NOT NULL AUTO_INCREMENT, `Name` VARCHAR(50) NOT NULL, PRIMARY KEY (`Id`), CONSTRAINT `fk_person_group` FOREIGN KEY (`Id`) REFERENCES `group` (`Id`) ) ENGINE=INNODB DEFAULT CHARSET=utf8; I'm using a local client to connect and run the test statement on MariaDB 5.5.41 - 46, on both Windows 2012 & CentOS 6.7....which all fail with the same error as above. You can work around this by either adding a database name to the reference, (kg_test1.group) or adding database context (i.e. use <db-name>) when logging in via the client, but it does not have to be the same database the table is being created in. This is a change in behaviour to MariaDB verisons prior to 5.5.41. |
When creating a table with a constraint which references a table without explicitly naming the database the statement fails with the following error.
{noformat} ERROR 1046 (3D000) at line ##@ No database selected. {noformat} The test statement used is as follows: {code:sql} CREATE TABLE `kg_test1`.`person` ( `Id` INT(11) NOT NULL AUTO_INCREMENT, `Name` VARCHAR(50) NOT NULL, PRIMARY KEY (`Id`), CONSTRAINT `fk_person_group` FOREIGN KEY (`Id`) REFERENCES `group` (`Id`) ) ENGINE=INNODB DEFAULT CHARSET=utf8; {code} I'm using a local client to connect and run the test statement on MariaDB 5.5.41 - 46, on both Windows 2012 & CentOS 6.7....which all fail with the same error as above. You can work around this by either adding a database name to the reference, (kg_test1.group) or adding database context (i.e. use <db-name>) when logging in via the client, but it does not have to be the same database the table is being created in. This is a change in behaviour to MariaDB verisons prior to 5.5.41. |
Status | Confirmed [ 10101 ] | In Progress [ 3 ] |
Assignee | Jan Lindström [ jplindst ] | Sergei Golubchik [ serg ] |
Status | In Progress [ 3 ] | In Review [ 10002 ] |
Fix Version/s | 5.5 [ 15800 ] | |
Fix Version/s | 10.0 [ 16000 ] | |
Fix Version/s | 10.1 [ 16100 ] |
Assignee | Sergei Golubchik [ serg ] | Jan Lindström [ jplindst ] |
Status | In Review [ 10002 ] | Stalled [ 10000 ] |
Component/s | Data Definition - Alter Table [ 10114 ] | |
Fix Version/s | 5.5.50 [ 22014 ] | |
Fix Version/s | 10.0.25 [ 21701 ] | |
Fix Version/s | 5.5 [ 15800 ] | |
Fix Version/s | 10.0 [ 16000 ] | |
Fix Version/s | 10.1 [ 16100 ] | |
Resolution | Fixed [ 1 ] | |
Status | Stalled [ 10000 ] | Closed [ 6 ] |
Workflow | MariaDB v3 [ 72618 ] | MariaDB v4 [ 149834 ] |
The change was introduced by this commit:
commit 0b28d7e048fa097280be54f9baffd202f7626bdd
Author: Praveenkumar Hulakund <praveenkumar.hulakund@oracle.com>
Date: Wed Sep 10 10:50:17 2014 +0530
Bug#18790730 - CROSS-DATABASE FOREIGN KEY WITHOUT PERMISSIONS
CHECK.
Analysis:
----------
Issue here is, while creating or altering the InnoDB table,
if the foreign key defined on the table references a parent
table on which the user has no access privileges then the
table is created without reporting any error.
Currently the privilege level REFERENCES_ACL is unused
and is not used for access evaluation while creating the
table with a foreign key constraint or adding the foreign
key constraint to a table. But when no privileges are granted
to user then also access evaluation on parent table is ignored.
Fix:
---------
For DMLs, irrelevant of the fact, support does not want any
changes to avoid permission checks on every operation.
So, as a fix, added a function "check_fk_parent_table_access"
to check whether any of the SELECT_ACL, INSERT_ACL, UDPATE_ACL,
DELETE_ACL or REFERENCE_ACL privileges are granted for user
at table level. If none of them is granted then error is reported.
This function is called during the table creation and alter
operation.
However, I can't say from the above whether the described side-effect is expected or not. Assigning to jplindst for an expert opinion.
Here is the complete test case:
--source include/have_innodb.inc
DROP DATABASE test;
CREATE DATABASE kg_test1;
CREATE TABLE `kg_test1`.`group` (
Id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `kg_test1`.`person` (
`Id` INT(11) NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(50) NOT NULL,
PRIMARY KEY (`Id`),
CONSTRAINT `fk_person_group` FOREIGN KEY (`Id`) REFERENCES `group` (`Id`)
) ENGINE=INNODB DEFAULT CHARSET=utf8;
SHOW WARNINGS;
DROP DATABASE kg_test1;
CREATE DATABASE test;