Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
be31afd1
Commit
be31afd1
authored
Aug 24, 2004
by
bell@sanja.is.com.ua
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed UNION support in view creation (BUG#4664)
parent
5abb148d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
55 deletions
+85
-55
mysql-test/r/view.result
mysql-test/r/view.result
+18
-2
mysql-test/t/view.test
mysql-test/t/view.test
+13
-1
sql/sql_view.cc
sql/sql_view.cc
+54
-52
No files found.
mysql-test/r/view.result
View file @
be31afd1
...
@@ -830,7 +830,7 @@ a b c
...
@@ -830,7 +830,7 @@ a b c
30 4 -60
30 4 -60
50 6 -100
50 6 -100
40 5 NULL
40 5 NULL
drop table t1;
drop table t1
, t2
;
drop view v1,v2,v3,v4,v5;
drop view v1,v2,v3,v4,v5;
create database mysqltest;
create database mysqltest;
create table mysqltest.t1 (a int, b int, primary key(a));
create table mysqltest.t1 (a int, b int, primary key(a));
...
@@ -1040,7 +1040,6 @@ CREATE VIEW v02 AS SELECT * FROM DUAL;
...
@@ -1040,7 +1040,6 @@ CREATE VIEW v02 AS SELECT * FROM DUAL;
ERROR HY000: No tables used
ERROR HY000: No tables used
SHOW TABLES;
SHOW TABLES;
Tables_in_test table_type
Tables_in_test table_type
t2 BASE TABLE
v4 VIEW
v4 VIEW
CREATE VIEW v1 AS SELECT EXISTS (SELECT 1 UNION SELECT 2);
CREATE VIEW v1 AS SELECT EXISTS (SELECT 1 UNION SELECT 2);
select * from v1;
select * from v1;
...
@@ -1058,3 +1057,20 @@ SHOW CREATE VIEW v1;
...
@@ -1058,3 +1057,20 @@ SHOW CREATE VIEW v1;
Table Create Table
Table Create Table
v1 CREATE VIEW test.v1 AS select sql_no_cache connection_id() AS `f1`,pi() AS `f2`,current_user() AS `f3`,version() AS `f4`
v1 CREATE VIEW test.v1 AS select sql_no_cache connection_id() AS `f1`,pi() AS `f2`,current_user() AS `f3`,version() AS `f4`
drop view v1;
drop view v1;
create table t1 (s1 int);
create table t2 (s2 int);
insert into t1 values (1), (2);
insert into t2 values (2), (3);
create view v1 as select * from t1,t2 union all select * from t1,t2;
select * from v1;
s1 s2
1 2
2 2
1 3
2 3
1 2
2 2
1 3
2 3
drop view v1;
drop tables t1, t2;
mysql-test/t/view.test
View file @
be31afd1
...
@@ -693,7 +693,7 @@ insert into v1 select c, b, a from t2;
...
@@ -693,7 +693,7 @@ insert into v1 select c, b, a from t2;
insert
into
v1
(
z
,
y
,
x
)
select
a
+
20
,
b
+
2
,
-
100
from
t2
;
insert
into
v1
(
z
,
y
,
x
)
select
a
+
20
,
b
+
2
,
-
100
from
t2
;
insert
into
v2
select
b
+
1
,
a
+
10
from
t2
;
insert
into
v2
select
b
+
1
,
a
+
10
from
t2
;
select
*
from
t1
;
select
*
from
t1
;
drop
table
t1
;
drop
table
t1
,
t2
;
drop
view
v1
,
v2
,
v3
,
v4
,
v5
;
drop
view
v1
,
v2
,
v3
,
v4
,
v5
;
#
#
...
@@ -1004,3 +1004,15 @@ drop table t1;
...
@@ -1004,3 +1004,15 @@ drop table t1;
CREATE
VIEW
v1
(
f1
,
f2
,
f3
,
f4
)
AS
SELECT
connection_id
(),
pi
(),
current_user
(),
version
();
CREATE
VIEW
v1
(
f1
,
f2
,
f3
,
f4
)
AS
SELECT
connection_id
(),
pi
(),
current_user
(),
version
();
SHOW
CREATE
VIEW
v1
;
SHOW
CREATE
VIEW
v1
;
drop
view
v1
;
drop
view
v1
;
#
# VIEW built over UNION
#
create
table
t1
(
s1
int
);
create
table
t2
(
s2
int
);
insert
into
t1
values
(
1
),
(
2
);
insert
into
t2
values
(
2
),
(
3
);
create
view
v1
as
select
*
from
t1
,
t2
union
all
select
*
from
t1
,
t2
;
select
*
from
v1
;
drop
view
v1
;
drop
tables
t1
,
t2
;
sql/sql_view.cc
View file @
be31afd1
...
@@ -54,7 +54,7 @@ int mysql_create_view(THD *thd,
...
@@ -54,7 +54,7 @@ int mysql_create_view(THD *thd,
TABLE_LIST
*
view
=
lex
->
unlink_first_table
(
&
link_to_local
);
TABLE_LIST
*
view
=
lex
->
unlink_first_table
(
&
link_to_local
);
TABLE_LIST
*
tables
=
lex
->
query_tables
;
TABLE_LIST
*
tables
=
lex
->
query_tables
;
TABLE_LIST
*
tbl
;
TABLE_LIST
*
tbl
;
SELECT_LEX
*
select_lex
=
&
lex
->
select_lex
;
SELECT_LEX
*
select_lex
=
&
lex
->
select_lex
,
*
sl
;
SELECT_LEX_UNIT
*
unit
=
&
lex
->
unit
;
SELECT_LEX_UNIT
*
unit
=
&
lex
->
unit
;
int
res
=
0
;
int
res
=
0
;
DBUG_ENTER
(
"mysql_create_view"
);
DBUG_ENTER
(
"mysql_create_view"
);
...
@@ -74,56 +74,59 @@ int mysql_create_view(THD *thd,
...
@@ -74,56 +74,59 @@ int mysql_create_view(THD *thd,
0
,
0
)
||
0
,
0
)
||
grant_option
&&
check_grant
(
thd
,
CREATE_VIEW_ACL
,
view
,
0
,
1
,
0
))
grant_option
&&
check_grant
(
thd
,
CREATE_VIEW_ACL
,
view
,
0
,
1
,
0
))
DBUG_RETURN
(
1
);
DBUG_RETURN
(
1
);
for
(
tbl
=
tables
;
tbl
;
tbl
=
tbl
->
next_local
)
for
(
sl
=
select_lex
;
sl
;
sl
=
sl
->
next_select
()
)
{
{
/*
for
(
tbl
=
sl
->
get_table_list
();
tbl
;
tbl
=
tbl
->
next_local
)
Ensure that we have some privilage on this table, more strict check
will be done on column level after preparation,
SELECT_ACL will be checked for sure for all fields because it is
listed first (if we have not rights to SELECT from whole table this
right will be written as tbl->grant.want_privilege and will be checked
later (except fields which need any privilege and can be updated).
*/
if
((
check_access
(
thd
,
SELECT_ACL
,
tbl
->
db
,
&
tbl
->
grant
.
privilege
,
0
,
1
)
||
grant_option
&&
check_grant
(
thd
,
SELECT_ACL
,
tbl
,
0
,
1
,
1
))
&&
(
check_access
(
thd
,
INSERT_ACL
,
tbl
->
db
,
&
tbl
->
grant
.
privilege
,
0
,
1
)
||
grant_option
&&
check_grant
(
thd
,
INSERT_ACL
,
tbl
,
0
,
1
,
1
))
&&
(
check_access
(
thd
,
DELETE_ACL
,
tbl
->
db
,
&
tbl
->
grant
.
privilege
,
0
,
1
)
||
grant_option
&&
check_grant
(
thd
,
DELETE_ACL
,
tbl
,
0
,
1
,
1
))
&&
(
check_access
(
thd
,
UPDATE_ACL
,
tbl
->
db
,
&
tbl
->
grant
.
privilege
,
0
,
1
)
||
grant_option
&&
check_grant
(
thd
,
UPDATE_ACL
,
tbl
,
0
,
1
,
1
))
)
{
{
my_printf_error
(
ER_TABLEACCESS_DENIED_ERROR
,
/*
ER
(
ER_TABLEACCESS_DENIED_ERROR
),
Ensure that we have some privilage on this table, more strict check
MYF
(
0
),
will be done on column level after preparation,
"ANY"
,
thd
->
priv_user
,
thd
->
host_or_ip
,
tbl
->
real_name
);
DBUG_RETURN
(
-
1
);
}
/* mark this table as table which will be checked after preparation */
tbl
->
table_in_first_from_clause
=
1
;
/*
SELECT_ACL will be checked for sure for all fields because it is
We need to check only SELECT_ACL for all normal fields, fields
listed first (if we have not rights to SELECT from whole table this
where we need any privilege will be pmarked later
right will be written as tbl->grant.want_privilege and will be checked
*/
later (except fields which need any privilege and can be updated).
tbl
->
grant
.
want_privilege
=
SELECT_ACL
;
*/
/*
if
((
check_access
(
thd
,
SELECT_ACL
,
tbl
->
db
,
Make sure that all rights are loaded to table 'grant' field.
&
tbl
->
grant
.
privilege
,
0
,
1
)
||
grant_option
&&
check_grant
(
thd
,
SELECT_ACL
,
tbl
,
0
,
1
,
1
))
&&
(
check_access
(
thd
,
INSERT_ACL
,
tbl
->
db
,
&
tbl
->
grant
.
privilege
,
0
,
1
)
||
grant_option
&&
check_grant
(
thd
,
INSERT_ACL
,
tbl
,
0
,
1
,
1
))
&&
(
check_access
(
thd
,
DELETE_ACL
,
tbl
->
db
,
&
tbl
->
grant
.
privilege
,
0
,
1
)
||
grant_option
&&
check_grant
(
thd
,
DELETE_ACL
,
tbl
,
0
,
1
,
1
))
&&
(
check_access
(
thd
,
UPDATE_ACL
,
tbl
->
db
,
&
tbl
->
grant
.
privilege
,
0
,
1
)
||
grant_option
&&
check_grant
(
thd
,
UPDATE_ACL
,
tbl
,
0
,
1
,
1
))
)
{
my_printf_error
(
ER_TABLEACCESS_DENIED_ERROR
,
ER
(
ER_TABLEACCESS_DENIED_ERROR
),
MYF
(
0
),
"ANY"
,
thd
->
priv_user
,
thd
->
host_or_ip
,
tbl
->
real_name
);
DBUG_RETURN
(
-
1
);
}
/* mark this table as table which will be checked after preparation */
tbl
->
table_in_first_from_clause
=
1
;
tbl->real_name will be correct name of table because VIEWs are
/*
not opened yet.
We need to check only SELECT_ACL for all normal fields, fields
*/
where we need any privilege will be pmarked later
fill_effective_table_privileges
(
thd
,
&
tbl
->
grant
,
tbl
->
db
,
*/
tbl
->
real_name
);
tbl
->
grant
.
want_privilege
=
SELECT_ACL
;
/*
Make sure that all rights are loaded to table 'grant' field.
tbl->real_name will be correct name of table because VIEWs are
not opened yet.
*/
fill_effective_table_privileges
(
thd
,
&
tbl
->
grant
,
tbl
->
db
,
tbl
->
real_name
);
}
}
}
if
(
&
lex
->
select_lex
!=
lex
->
all_selects_list
)
if
(
&
lex
->
select_lex
!=
lex
->
all_selects_list
)
...
@@ -145,12 +148,10 @@ int mysql_create_view(THD *thd,
...
@@ -145,12 +148,10 @@ int mysql_create_view(THD *thd,
}
}
/*
/*
Mark fields for special privilege check (any privilege)
Mark fields for special privilege check (any privilege)
'if' should be changed if we made updateable UNION.
*/
*/
if
(
lex
->
select_lex
.
next_select
()
==
0
)
for
(
sl
=
select_lex
;
sl
;
sl
=
sl
->
next_select
()
)
{
{
List_iterator_fast
<
Item
>
it
(
lex
->
select_lex
.
item_list
);
List_iterator_fast
<
Item
>
it
(
sl
->
item_list
);
Item
*
item
;
Item
*
item
;
while
((
item
=
it
++
))
while
((
item
=
it
++
))
{
{
...
@@ -235,9 +236,10 @@ int mysql_create_view(THD *thd,
...
@@ -235,9 +236,10 @@ int mysql_create_view(THD *thd,
/*
/*
Compare/check grants on view with grants of underlaying tables
Compare/check grants on view with grants of underlaying tables
*/
*/
for
(
sl
=
select_lex
;
sl
;
sl
=
sl
->
next_select
())
{
{
char
*
db
=
view
->
db
?
view
->
db
:
thd
->
db
;
char
*
db
=
view
->
db
?
view
->
db
:
thd
->
db
;
List_iterator_fast
<
Item
>
it
(
s
elect_lex
->
item_list
);
List_iterator_fast
<
Item
>
it
(
s
l
->
item_list
);
Item
*
item
;
Item
*
item
;
fill_effective_table_privileges
(
thd
,
&
view
->
grant
,
db
,
fill_effective_table_privileges
(
thd
,
&
view
->
grant
,
db
,
view
->
real_name
);
view
->
real_name
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment