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
4304dbc4
Commit
4304dbc4
authored
Oct 09, 2012
by
unknown
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-616 fix (MySQL fix accepted)
parent
72ab07c1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
130 additions
and
35 deletions
+130
-35
mysql-test/r/user_var.result
mysql-test/r/user_var.result
+35
-3
mysql-test/t/user_var.test
mysql-test/t/user_var.test
+28
-0
sql/item_func.h
sql/item_func.h
+9
-0
sql/sql_select.cc
sql/sql_select.cc
+58
-32
No files found.
mysql-test/r/user_var.result
View file @
4304dbc4
...
...
@@ -348,10 +348,10 @@ select @a:=f3, count(f3) from t1 group by 1 desc;
1.5 4
select @a:=f4, count(f4) from t1 group by 1 desc;
@a:=f4 count(f4)
4.6 1
3.6 2
2.6 1
1.6 4
1.6 1
1.6 2
1.6 1
drop table t1;
create table t1 (f1 int);
insert into t1 values (2), (1);
...
...
@@ -464,3 +464,35 @@ GROUP BY @b:=(SELECT COUNT(*) > t2.a);
1
DROP TABLE t1;
End of 5.1 tests
CREATE TABLE t1(a INT);
INSERT INTO t1 VALUES (0);
SELECT DISTINCT POW(COUNT(*), @a:=(SELECT 1 FROM t1 LEFT JOIN t1 AS t2 ON @a))
AS b FROM t1 GROUP BY a;
b
1
SELECT @a;
@a
1
DROP TABLE t1;
CREATE TABLE t1(f1 INT, f2 INT);
INSERT INTO t1 VALUES (1,2),(2,3),(3,1);
CREATE TABLE t2(a INT);
INSERT INTO t2 VALUES (1);
SET @var=NULL;
SELECT @var:=(SELECT f2 FROM t2 WHERE @var) FROM t1 GROUP BY f1 ORDER BY f2 DESC
LIMIT 1;
@var:=(SELECT f2 FROM t2 WHERE @var)
NULL
SELECT @var;
@var
NULL
DROP TABLE t1, t2;
CREATE TABLE t1(a INT);
INSERT INTO t1 VALUES (0),(1),(3);
SELECT DISTINCT POW(COUNT(distinct a), @a:=(SELECT 1 FROM t1 LEFT JOIN t1 AS t2 ON @a limit 1)) AS b FROM t1 GROUP BY a;
b
1
SELECT @a;
@a
1
DROP TABLE t1;
mysql-test/t/user_var.test
View file @
4304dbc4
...
...
@@ -377,3 +377,31 @@ GROUP BY @b:=(SELECT COUNT(*) > t2.a);
DROP
TABLE
t1
;
--
echo
End
of
5.1
tests
#
# MDEV-616 LP BUG#1002126
# Bug #11764371 57196: MORE FUN WITH ASSERTION: !TABLE->FILE ||
# TABLE->FILE->INITED == HANDLER::
#
CREATE
TABLE
t1
(
a
INT
);
INSERT
INTO
t1
VALUES
(
0
);
SELECT
DISTINCT
POW
(
COUNT
(
*
),
@
a
:=
(
SELECT
1
FROM
t1
LEFT
JOIN
t1
AS
t2
ON
@
a
))
AS
b
FROM
t1
GROUP
BY
a
;
SELECT
@
a
;
DROP
TABLE
t1
;
CREATE
TABLE
t1
(
f1
INT
,
f2
INT
);
INSERT
INTO
t1
VALUES
(
1
,
2
),(
2
,
3
),(
3
,
1
);
CREATE
TABLE
t2
(
a
INT
);
INSERT
INTO
t2
VALUES
(
1
);
SET
@
var
=
NULL
;
SELECT
@
var
:=
(
SELECT
f2
FROM
t2
WHERE
@
var
)
FROM
t1
GROUP
BY
f1
ORDER
BY
f2
DESC
LIMIT
1
;
SELECT
@
var
;
DROP
TABLE
t1
,
t2
;
CREATE
TABLE
t1
(
a
INT
);
INSERT
INTO
t1
VALUES
(
0
),(
1
),(
3
);
SELECT
DISTINCT
POW
(
COUNT
(
distinct
a
),
@
a
:=
(
SELECT
1
FROM
t1
LEFT
JOIN
t1
AS
t2
ON
@
a
limit
1
))
AS
b
FROM
t1
GROUP
BY
a
;
SELECT
@
a
;
DROP
TABLE
t1
;
sql/item_func.h
View file @
4304dbc4
...
...
@@ -1441,6 +1441,15 @@ class Item_func_set_user_var :public Item_func
:
Item_func
(
b
),
cached_result_type
(
INT_RESULT
),
entry
(
NULL
),
entry_thread_id
(
0
),
name
(
a
)
{}
Item_func_set_user_var
(
Item_func_set_user_var
*
item
)
:
Item_func
(
item
),
cached_result_type
(
item
->
cached_result_type
),
entry
(
item
->
entry
),
entry_thread_id
(
item
->
entry_thread_id
),
value
(
item
->
value
),
decimal_buff
(
item
->
decimal_buff
),
null_item
(
item
->
null_item
),
save_result
(
item
->
save_result
),
name
(
item
->
name
)
{
//fixed= 1;
}
enum
Functype
functype
()
const
{
return
SUSERVAR_FUNC
;
}
double
val_real
();
longlong
val_int
();
...
...
sql/sql_select.cc
View file @
4304dbc4
...
...
@@ -16237,40 +16237,66 @@ change_to_use_tmp_fields(THD *thd, Item **ref_pointer_array,
res_selected_fields
.
empty
();
res_all_fields
.
empty
();
uint
i
,
border
=
all_fields
.
elements
-
elements
;
for
(
i
=
0
;
(
item
=
it
++
);
i
++
)
uint
border
=
all_fields
.
elements
-
elements
;
for
(
uint
i
=
0
;
(
item
=
it
++
);
i
++
)
{
Field
*
field
;
if
((
item
->
with_sum_func
&&
item
->
type
()
!=
Item
::
SUM_FUNC_ITEM
)
||
(
item
->
type
()
==
Item
::
FUNC_ITEM
&&
((
Item_func
*
)
item
)
->
functype
()
==
Item_func
::
SUSERVAR_FUNC
))
if
(
item
->
with_sum_func
&&
item
->
type
()
!=
Item
::
SUM_FUNC_ITEM
)
item_field
=
item
;
else
else
if
(
item
->
type
()
==
Item
::
FIELD_ITEM
)
item_field
=
item
->
get_tmp_table_item
(
thd
);
else
if
(
item
->
type
()
==
Item
::
FUNC_ITEM
&&
((
Item_func
*
)
item
)
->
functype
()
==
Item_func
::
SUSERVAR_FUNC
)
{
if
(
item
->
type
()
==
Item
::
FIELD_ITEM
)
field
=
item
->
get_tmp_table_field
();
if
(
field
!=
NULL
)
{
item_field
=
item
->
get_tmp_table_item
(
thd
);
/*
Replace "@:=<expression>" with "@:=<tmp table column>". Otherwise,
we would re-evaluate <expression>, and if expression were
a subquery, this would access already-unlocked tables.
*/
Item_func_set_user_var
*
suv
=
new
Item_func_set_user_var
((
Item_func_set_user_var
*
)
item
);
Item_field
*
new_field
=
new
Item_field
(
field
);
if
(
!
suv
||
!
new_field
||
suv
->
fix_fields
(
thd
,
(
Item
**
)
&
suv
))
DBUG_RETURN
(
true
);
// Fatal error
((
Item
*
)
suv
)
->
name
=
item
->
name
;
/*
We are replacing the argument of Item_func_set_user_var after its
value has been read. The argument's null_value should be set by
now, so we must set it explicitly for the replacement argument
since the null_value may be read without any preceeding call to
val_*().
*/
new_field
->
update_null_value
();
List
<
Item
>
list
;
list
.
push_back
(
new_field
);
suv
->
set_arguments
(
list
);
item_field
=
suv
;
}
else
if
((
field
=
item
->
get_tmp_table_field
()))
else
item_field
=
item
;
}
else
if
((
field
=
item
->
get_tmp_table_field
()))
{
if
(
item
->
type
()
==
Item
::
SUM_FUNC_ITEM
&&
field
->
table
->
group
)
item_field
=
((
Item_sum
*
)
item
)
->
result_item
(
field
);
else
item_field
=
(
Item
*
)
new
Item_field
(
field
);
if
(
!
item_field
)
DBUG_RETURN
(
true
);
// Fatal error
if
(
item
->
real_item
()
->
type
()
!=
Item
::
FIELD_ITEM
)
field
->
orig_table
=
0
;
item_field
->
name
=
item
->
name
;
if
(
item
->
type
()
==
Item
::
REF_ITEM
)
{
if
(
item
->
type
()
==
Item
::
SUM_FUNC_ITEM
&&
field
->
table
->
group
)
item_field
=
((
Item_sum
*
)
item
)
->
result_item
(
field
);
else
item_field
=
(
Item
*
)
new
Item_field
(
field
);
if
(
!
item_field
)
DBUG_RETURN
(
TRUE
);
// Fatal error
if
(
item
->
real_item
()
->
type
()
!=
Item
::
FIELD_ITEM
)
field
->
orig_table
=
0
;
item_field
->
name
=
item
->
name
;
if
(
item
->
type
()
==
Item
::
REF_ITEM
)
{
Item_field
*
ifield
=
(
Item_field
*
)
item_field
;
Item_ref
*
iref
=
(
Item_ref
*
)
item
;
ifield
->
table_name
=
iref
->
table_name
;
ifield
->
db_name
=
iref
->
db_name
;
}
Item_field
*
ifield
=
(
Item_field
*
)
item_field
;
Item_ref
*
iref
=
(
Item_ref
*
)
item
;
ifield
->
table_name
=
iref
->
table_name
;
ifield
->
db_name
=
iref
->
db_name
;
}
#ifndef DBUG_OFF
if
(
!
item_field
->
name
)
{
...
...
@@ -16282,20 +16308,20 @@ change_to_use_tmp_fields(THD *thd, Item **ref_pointer_array,
item_field
->
name
=
sql_strmake
(
str
.
ptr
(),
str
.
length
());
}
#endif
}
else
item_field
=
item
;
}
else
item_field
=
item
;
res_all_fields
.
push_back
(
item_field
);
ref_pointer_array
[((
i
<
border
)
?
all_fields
.
elements
-
i
-
1
:
i
-
border
)]
=
item_field
;
}
List_iterator_fast
<
Item
>
itr
(
res_all_fields
);
for
(
i
=
0
;
i
<
border
;
i
++
)
for
(
uint
i
=
0
;
i
<
border
;
i
++
)
itr
++
;
itr
.
sublist
(
res_selected_fields
,
elements
);
DBUG_RETURN
(
FALSE
);
DBUG_RETURN
(
false
);
}
...
...
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