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
ccee4036
Commit
ccee4036
authored
Apr 24, 2006
by
unknown
Browse files
Options
Browse Files
Download
Plain Diff
Manually merged
sql/item.cc: Auto merged sql/sql_select.cc: Auto merged
parents
2a138695
4b7c4cd2
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
48 additions
and
2 deletions
+48
-2
mysql-test/r/having.result
mysql-test/r/having.result
+13
-0
mysql-test/t/having.test
mysql-test/t/having.test
+13
-0
sql/item.cc
sql/item.cc
+16
-2
sql/share/errmsg.txt
sql/share/errmsg.txt
+2
-0
sql/sql_select.cc
sql/sql_select.cc
+4
-0
No files found.
mysql-test/r/having.result
View file @
ccee4036
...
...
@@ -392,3 +392,16 @@ HAVING HU.PROJ.CITY = HU.STAFF.CITY);
EMPNUM GRADE*1000
E3 13000
DROP SCHEMA HU;
USE test;
create table t1(f1 int);
select f1 from t1 having max(f1)=f1;
f1
select f1 from t1 group by f1 having max(f1)=f1;
f1
set session sql_mode='ONLY_FULL_GROUP_BY';
select f1 from t1 having max(f1)=f1;
ERROR 42000: non-grouping field 'f1' is used in HAVING clause
select f1 from t1 group by f1 having max(f1)=f1;
f1
set session sql_mode='';
drop table t1;
mysql-test/t/having.test
View file @
ccee4036
...
...
@@ -393,3 +393,16 @@ SELECT EMPNUM, GRADE*1000
HAVING
HU
.
PROJ
.
CITY
=
HU
.
STAFF
.
CITY
);
DROP
SCHEMA
HU
;
USE
test
;
#
# Bug#18739: non-standard HAVING extension was allowed in strict ANSI sql mode.
#
create
table
t1
(
f1
int
);
select
f1
from
t1
having
max
(
f1
)
=
f1
;
select
f1
from
t1
group
by
f1
having
max
(
f1
)
=
f1
;
set
session
sql_mode
=
'ONLY_FULL_GROUP_BY'
;
--
error
1461
select
f1
from
t1
having
max
(
f1
)
=
f1
;
select
f1
from
t1
group
by
f1
having
max
(
f1
)
=
f1
;
set
session
sql_mode
=
''
;
drop
table
t1
;
sql/item.cc
View file @
ccee4036
...
...
@@ -3137,7 +3137,8 @@ static Item** find_field_in_group_list(Item *find_item, ORDER *group_list)
both clauses contain different fields with the same names, a warning is
issued that name of 'ref' is ambiguous. We extend ANSI SQL in that when no
GROUP BY column is found, then a HAVING name is resolved as a possibly
derived SELECT column.
derived SELECT column. This extension is allowed only if the
MODE_ONLY_FULL_GROUP_BY sql mode isn't enabled.
NOTES
The resolution procedure is:
...
...
@@ -3147,7 +3148,9 @@ static Item** find_field_in_group_list(Item *find_item, ORDER *group_list)
in the GROUP BY clause of Q.
- If found different columns with the same name in GROUP BY and SELECT
- issue a warning and return the GROUP BY column,
- otherwise return the found SELECT column.
- otherwise
- if the MODE_ONLY_FULL_GROUP_BY mode is enabled return error
- else return the found SELECT column.
RETURN
...
...
@@ -3192,6 +3195,17 @@ resolve_ref_in_select_and_group(THD *thd, Item_ident *ref, SELECT_LEX *select)
}
}
if
(
thd
->
variables
.
sql_mode
&
MODE_ONLY_FULL_GROUP_BY
&&
select_ref
!=
not_found_item
&&
!
group_by_ref
)
{
/*
Report the error if fields was found only in the SELECT item list and
the strict mode is enabled.
*/
my_error
(
ER_NON_GROUPING_FIELD_USED
,
MYF
(
0
),
ref
->
name
,
"HAVING"
);
return
NULL
;
}
if
(
select_ref
!=
not_found_item
||
group_by_ref
)
{
if
(
select_ref
!=
not_found_item
&&
!
ambiguous_fields
)
...
...
sql/share/errmsg.txt
View file @
ccee4036
...
...
@@ -5615,3 +5615,5 @@ ER_MAX_PREPARED_STMT_COUNT_REACHED 42000
eng "Can't create more than max_prepared_stmt_count statements (current value: %lu)"
ER_VIEW_RECURSIVE
eng "`%-.64s`.`%-.64s` contain view recursion"
ER_NON_GROUPING_FIELD_USED 42000
eng "non-grouping field '%-.64s' is used in %-.64s clause"
sql/sql_select.cc
View file @
ccee4036
...
...
@@ -12613,6 +12613,10 @@ setup_group(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
if
(
item
->
type
()
!=
Item
::
SUM_FUNC_ITEM
&&
!
item
->
marker
&&
!
item
->
const_item
())
{
/*
TODO: change ER_WRONG_FIELD_WITH_GROUP to more detailed
ER_NON_GROUPING_FIELD_USED
*/
my_error
(
ER_WRONG_FIELD_WITH_GROUP
,
MYF
(
0
),
item
->
full_name
());
return
1
;
}
...
...
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