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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
d2cfad16
Commit
d2cfad16
authored
Jan 06, 2006
by
igor@rurik.mysql.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed bug #16016: MIN/MAX optimization was not applied to views.
parent
d8a4aafe
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
5 deletions
+58
-5
mysql-test/r/view.result
mysql-test/r/view.result
+29
-0
mysql-test/t/view.test
mysql-test/t/view.test
+24
-0
sql/opt_sum.cc
sql/opt_sum.cc
+5
-5
No files found.
mysql-test/r/view.result
View file @
d2cfad16
...
...
@@ -2475,3 +2475,32 @@ alias1 alias2
5 5
drop view v2, v1;
drop table t1;
CREATE TABLE t1 (a int PRIMARY KEY, b int);
INSERT INTO t1 VALUES (2,20), (3,10), (1,10), (0,30), (5,10);
CREATE VIEW v1 AS SELECT * FROM t1;
SELECT MAX(a) FROM t1;
MAX(a)
5
SELECT MAX(a) FROM v1;
MAX(a)
5
EXPLAIN SELECT MAX(a) FROM t1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
EXPLAIN SELECT MAX(a) FROM v1;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
SELECT MIN(a) FROM t1;
MIN(a)
0
SELECT MIN(a) FROM v1;
MIN(a)
0
EXPLAIN SELECT MIN(a) FROM t1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
EXPLAIN SELECT MIN(a) FROM v1;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
DROP VIEW v1;
DROP TABLE t1;
mysql-test/t/view.test
View file @
d2cfad16
...
...
@@ -2339,3 +2339,27 @@ order by v2.receipt_id;
drop
view
v2
,
v1
;
drop
table
t1
;
#
# Bug#16016: MIN/MAX optimization for views
#
CREATE
TABLE
t1
(
a
int
PRIMARY
KEY
,
b
int
);
INSERT
INTO
t1
VALUES
(
2
,
20
),
(
3
,
10
),
(
1
,
10
),
(
0
,
30
),
(
5
,
10
);
CREATE
VIEW
v1
AS
SELECT
*
FROM
t1
;
SELECT
MAX
(
a
)
FROM
t1
;
SELECT
MAX
(
a
)
FROM
v1
;
EXPLAIN
SELECT
MAX
(
a
)
FROM
t1
;
EXPLAIN
SELECT
MAX
(
a
)
FROM
v1
;
SELECT
MIN
(
a
)
FROM
t1
;
SELECT
MIN
(
a
)
FROM
v1
;
EXPLAIN
SELECT
MIN
(
a
)
FROM
t1
;
EXPLAIN
SELECT
MIN
(
a
)
FROM
v1
;
DROP
VIEW
v1
;
DROP
TABLE
t1
;
sql/opt_sum.cc
View file @
d2cfad16
...
...
@@ -180,14 +180,14 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds)
indexes to find the key.
*/
Item
*
expr
=
item_sum
->
args
[
0
];
if
(
expr
->
type
()
==
Item
::
FIELD_ITEM
)
if
(
expr
->
real_item
()
->
type
()
==
Item
::
FIELD_ITEM
)
{
byte
key_buff
[
MAX_KEY_LENGTH
];
TABLE_REF
ref
;
uint
range_fl
,
prefix_len
;
ref
.
key_buff
=
key_buff
;
Item_field
*
item_field
=
(
(
Item_field
*
)
expr
);
Item_field
*
item_field
=
(
Item_field
*
)
(
expr
->
real_item
()
);
TABLE
*
table
=
item_field
->
field
->
table
;
/*
...
...
@@ -267,14 +267,14 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds)
indexes to find the key.
*/
Item
*
expr
=
item_sum
->
args
[
0
];
if
(
expr
->
type
()
==
Item
::
FIELD_ITEM
)
if
(
expr
->
real_item
()
->
type
()
==
Item
::
FIELD_ITEM
)
{
byte
key_buff
[
MAX_KEY_LENGTH
];
TABLE_REF
ref
;
uint
range_fl
,
prefix_len
;
uint
range_fl
,
prefix_len
;
ref
.
key_buff
=
key_buff
;
Item_field
*
item_field
=
((
Item_field
*
)
expr
);
Item_field
*
item_field
=
(
Item_field
*
)
(
expr
->
real_item
()
);
TABLE
*
table
=
item_field
->
field
->
table
;
/*
...
...
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