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
3bf0a8e0
Commit
3bf0a8e0
authored
Apr 23, 2006
by
unknown
Browse files
Options
Browse Files
Download
Plain Diff
Merge bk-internal.mysql.com:/home/bk/mysql-5.1-new
into mysql.com:/opt/local/work/mysql-5.1-merge
parents
c6a0bfba
04f93ca0
Changes
19
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
494 additions
and
279 deletions
+494
-279
mysql-test/r/status.result
mysql-test/r/status.result
+20
-0
mysql-test/r/trigger.result
mysql-test/r/trigger.result
+13
-0
mysql-test/t/status.test
mysql-test/t/status.test
+101
-1
mysql-test/t/trigger.test
mysql-test/t/trigger.test
+28
-0
sql/item.cc
sql/item.cc
+0
-16
sql/item.h
sql/item.h
+0
-12
sql/item_create.cc
sql/item_create.cc
+2
-8
sql/item_func.cc
sql/item_func.cc
+25
-0
sql/item_func.h
sql/item_func.h
+12
-0
sql/mysql_priv.h
sql/mysql_priv.h
+1
-0
sql/mysqld.cc
sql/mysqld.cc
+59
-17
sql/sp_head.cc
sql/sp_head.cc
+11
-11
sql/sp_head.h
sql/sp_head.h
+3
-3
sql/sp_pcontext.cc
sql/sp_pcontext.cc
+81
-80
sql/sp_pcontext.h
sql/sp_pcontext.h
+78
-52
sql/sp_rcontext.cc
sql/sp_rcontext.cc
+12
-12
sql/sp_rcontext.h
sql/sp_rcontext.h
+4
-4
sql/sql_parse.cc
sql/sql_parse.cc
+0
-21
sql/sql_yacc.yy
sql/sql_yacc.yy
+44
-42
No files found.
mysql-test/r/status.result
View file @
3bf0a8e0
...
...
@@ -23,3 +23,23 @@ select 1;
show status like 'last_query_cost';
Variable_name Value
Last_query_cost 0.000000
FLUSH STATUS;
SHOW STATUS LIKE 'max_used_connections';
Variable_name Value
Max_used_connections 1
SET @save_thread_cache_size=@@thread_cache_size;
SET GLOBAL thread_cache_size=3;
SHOW STATUS LIKE 'max_used_connections';
Variable_name Value
Max_used_connections 3
FLUSH STATUS;
SHOW STATUS LIKE 'max_used_connections';
Variable_name Value
Max_used_connections 2
SHOW STATUS LIKE 'max_used_connections';
Variable_name Value
Max_used_connections 3
SHOW STATUS LIKE 'max_used_connections';
Variable_name Value
Max_used_connections 4
SET GLOBAL thread_cache_size=@save_thread_cache_size;
mysql-test/r/trigger.result
View file @
3bf0a8e0
...
...
@@ -952,3 +952,16 @@ load data infile '../std_data_ln/words.dat' into table t1 (a) set b:= f1();
drop table t1;
drop function f1;
drop function f2;
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (
conn_id INT,
trigger_conn_id INT
);
CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW
SET NEW.trigger_conn_id = CONNECTION_ID();
INSERT INTO t1 (conn_id, trigger_conn_id) VALUES (CONNECTION_ID(), -1);
INSERT INTO t1 (conn_id, trigger_conn_id) VALUES (CONNECTION_ID(), -1);
SELECT * FROM t1 WHERE conn_id != trigger_conn_id;
conn_id trigger_conn_id
DROP TRIGGER t1_bi;
DROP TABLE t1;
mysql-test/t/status.test
View file @
3bf0a8e0
...
...
@@ -36,11 +36,111 @@ reap;
show
status
like
'Table_lock%'
;
drop
table
t1
;
disconnect
con2
;
disconnect
con1
;
connection
default
;
# End of 4.1 tests
#
# l
o
st_query_cost
# l
a
st_query_cost
#
select
1
;
show
status
like
'last_query_cost'
;
#
# Test for Bug #15933 max_used_connections is wrong after FLUSH STATUS
# if connections are cached
#
#
# The first suggested fix from the bug report was chosen
# (see http://bugs.mysql.com/bug.php?id=15933):
#
# a) On flushing the status, set max_used_connections to
# threads_connected, not to 0.
#
# b) Check if it is necessary to increment max_used_connections when
# taking a thread from the cache as well as when creating new threads
#
# Wait for at most $disconnect_timeout seconds for disconnects to finish.
let
$disconnect_timeout
=
10
;
# Wait for any previous disconnects to finish.
FLUSH
STATUS
;
--
disable_query_log
--
disable_result_log
eval
SET
@
wait_left
=
$disconnect_timeout
;
let
$max_used_connections
=
`SHOW STATUS LIKE 'max_used_connections'`
;
eval
SET
@
max_used_connections
=
SUBSTRING
(
'$max_used_connections'
,
21
)
+
0
;
let
$wait_more
=
`SELECT @max_used_connections != 1 && @wait_left > 0`
;
while
(
$wait_more
)
{
sleep
1
;
FLUSH
STATUS
;
SET
@
wait_left
=
@
wait_left
-
1
;
let
$max_used_connections
=
`SHOW STATUS LIKE 'max_used_connections'`
;
eval
SET
@
max_used_connections
=
SUBSTRING
(
'$max_used_connections'
,
21
)
+
0
;
let
$wait_more
=
`SELECT @max_used_connections != 1 && @wait_left > 0`
;
}
--
enable_query_log
--
enable_result_log
# Prerequisite.
SHOW
STATUS
LIKE
'max_used_connections'
;
# Save original setting.
SET
@
save_thread_cache_size
=@@
thread_cache_size
;
SET
GLOBAL
thread_cache_size
=
3
;
connect
(
con1
,
localhost
,
root
,,);
connect
(
con2
,
localhost
,
root
,,);
connection
con1
;
disconnect
con2
;
# Check that max_used_connections still reflects maximum value.
SHOW
STATUS
LIKE
'max_used_connections'
;
# Check that after flush max_used_connections equals to current number
# of connections. First wait for previous disconnect to finish.
FLUSH
STATUS
;
--
disable_query_log
--
disable_result_log
eval
SET
@
wait_left
=
$disconnect_timeout
;
let
$max_used_connections
=
`SHOW STATUS LIKE 'max_used_connections'`
;
eval
SET
@
max_used_connections
=
SUBSTRING
(
'$max_used_connections'
,
21
)
+
0
;
let
$wait_more
=
`SELECT @max_used_connections != 2 && @wait_left > 0`
;
while
(
$wait_more
)
{
sleep
1
;
FLUSH
STATUS
;
SET
@
wait_left
=
@
wait_left
-
1
;
let
$max_used_connections
=
`SHOW STATUS LIKE 'max_used_connections'`
;
eval
SET
@
max_used_connections
=
SUBSTRING
(
'$max_used_connections'
,
21
)
+
0
;
let
$wait_more
=
`SELECT @max_used_connections != 2 && @wait_left > 0`
;
}
--
enable_query_log
--
enable_result_log
# Check that we don't count disconnected thread any longer.
SHOW
STATUS
LIKE
'max_used_connections'
;
# Check that max_used_connections is updated when cached thread is
# reused...
connect
(
con2
,
localhost
,
root
,,);
SHOW
STATUS
LIKE
'max_used_connections'
;
# ...and when new thread is created.
connect
(
con3
,
localhost
,
root
,,);
SHOW
STATUS
LIKE
'max_used_connections'
;
# Restore original setting.
connection
default
;
SET
GLOBAL
thread_cache_size
=@
save_thread_cache_size
;
disconnect
con3
;
disconnect
con2
;
disconnect
con1
;
# End of 5.0 tests
mysql-test/t/trigger.test
View file @
3bf0a8e0
...
...
@@ -1114,3 +1114,31 @@ load data infile '../std_data_ln/words.dat' into table t1 (a) set b:= f1();
drop
table
t1
;
drop
function
f1
;
drop
function
f2
;
#
# Test for Bug #16461 connection_id() does not work properly inside trigger
#
--
disable_warnings
DROP
TABLE
IF
EXISTS
t1
;
--
enable_warnings
CREATE
TABLE
t1
(
conn_id
INT
,
trigger_conn_id
INT
);
CREATE
TRIGGER
t1_bi
BEFORE
INSERT
ON
t1
FOR
EACH
ROW
SET
NEW
.
trigger_conn_id
=
CONNECTION_ID
();
INSERT
INTO
t1
(
conn_id
,
trigger_conn_id
)
VALUES
(
CONNECTION_ID
(),
-
1
);
connect
(
con1
,
localhost
,
root
,,);
INSERT
INTO
t1
(
conn_id
,
trigger_conn_id
)
VALUES
(
CONNECTION_ID
(),
-
1
);
connection
default
;
disconnect
con1
;
SELECT
*
FROM
t1
WHERE
conn_id
!=
trigger_conn_id
;
DROP
TRIGGER
t1_bi
;
DROP
TABLE
t1
;
# End of 5.0 tests
sql/item.cc
View file @
3bf0a8e0
...
...
@@ -644,22 +644,6 @@ Item *Item_num::safe_charset_converter(CHARSET_INFO *tocs)
}
Item
*
Item_static_int_func
::
safe_charset_converter
(
CHARSET_INFO
*
tocs
)
{
Item_string
*
conv
;
char
buf
[
64
];
String
*
s
,
tmp
(
buf
,
sizeof
(
buf
),
&
my_charset_bin
);
s
=
val_str
(
&
tmp
);
if
((
conv
=
new
Item_static_string_func
(
func_name
,
s
->
ptr
(),
s
->
length
(),
s
->
charset
())))
{
conv
->
str_value
.
copy
();
conv
->
str_value
.
mark_as_const
();
}
return
conv
;
}
Item
*
Item_static_float_func
::
safe_charset_converter
(
CHARSET_INFO
*
tocs
)
{
Item_string
*
conv
;
...
...
sql/item.h
View file @
3bf0a8e0
...
...
@@ -1431,18 +1431,6 @@ class Item_int :public Item_num
};
class
Item_static_int_func
:
public
Item_int
{
const
char
*
func_name
;
public:
Item_static_int_func
(
const
char
*
str_arg
,
longlong
i
,
uint
length
)
:
Item_int
(
NullS
,
i
,
length
),
func_name
(
str_arg
)
{}
Item
*
safe_charset_converter
(
CHARSET_INFO
*
tocs
);
void
print
(
String
*
str
)
{
str
->
append
(
func_name
);
}
};
class
Item_uint
:
public
Item_int
{
public:
...
...
sql/item_create.cc
View file @
3bf0a8e0
...
...
@@ -71,14 +71,8 @@ Item *create_func_ceiling(Item* a)
Item
*
create_func_connection_id
(
void
)
{
THD
*
thd
=
current_thd
;
thd
->
lex
->
safe_to_cache_query
=
0
;
return
new
Item_static_int_func
(
"connection_id()"
,
(
longlong
)
((
thd
->
slave_thread
)
?
thd
->
variables
.
pseudo_thread_id
:
thd
->
thread_id
),
10
);
current_thd
->
lex
->
safe_to_cache_query
=
0
;
return
new
Item_func_connection_id
();
}
Item
*
create_func_conv
(
Item
*
a
,
Item
*
b
,
Item
*
c
)
...
...
sql/item_func.cc
View file @
3bf0a8e0
...
...
@@ -561,6 +561,31 @@ String *Item_int_func::val_str(String *str)
}
void
Item_func_connection_id
::
fix_length_and_dec
()
{
Item_int_func
::
fix_length_and_dec
();
max_length
=
10
;
}
bool
Item_func_connection_id
::
fix_fields
(
THD
*
thd
,
Item
**
ref
)
{
if
(
Item_int_func
::
fix_fields
(
thd
,
ref
))
return
TRUE
;
/*
To replicate CONNECTION_ID() properly we should use
pseudo_thread_id on slave, which contains the value of thread_id
on master.
*/
value
=
((
thd
->
slave_thread
)
?
thd
->
variables
.
pseudo_thread_id
:
thd
->
thread_id
);
return
FALSE
;
}
/*
Check arguments here to determine result's type for a numeric
function of two arguments.
...
...
sql/item_func.h
View file @
3bf0a8e0
...
...
@@ -279,6 +279,18 @@ class Item_int_func :public Item_func
};
class
Item_func_connection_id
:
public
Item_int_func
{
longlong
value
;
public:
const
char
*
func_name
()
const
{
return
"connection_id"
;
}
void
fix_length_and_dec
();
bool
fix_fields
(
THD
*
thd
,
Item
**
ref
);
longlong
val_int
()
{
DBUG_ASSERT
(
fixed
==
1
);
return
value
;
}
};
class
Item_func_signed
:
public
Item_int_func
{
public:
...
...
sql/mysql_priv.h
View file @
3bf0a8e0
...
...
@@ -1408,6 +1408,7 @@ File open_binlog(IO_CACHE *log, const char *log_file_name,
/* mysqld.cc */
extern
void
MYSQLerror
(
const
char
*
);
void
refresh_status
(
THD
*
thd
);
/* item_func.cc */
extern
bool
check_reserved_words
(
LEX_STRING
*
name
);
...
...
sql/mysqld.cc
View file @
3bf0a8e0
...
...
@@ -1755,17 +1755,6 @@ void end_thread(THD *thd, bool put_in_cache)
}
/* Start a cached thread. LOCK_thread_count is locked on entry */
static
void
start_cached_thread
(
THD
*
thd
)
{
thread_cache
.
append
(
thd
);
wake_thread
++
;
thread_count
++
;
pthread_cond_signal
(
&
COND_thread_cache
);
}
void
flush_thread_cache
()
{
(
void
)
pthread_mutex_lock
(
&
LOCK_thread_count
);
...
...
@@ -3929,6 +3918,25 @@ static bool read_init_file(char *file_name)
#ifndef EMBEDDED_LIBRARY
/*
Create new thread to handle incoming connection.
SYNOPSIS
create_new_thread()
thd in/out Thread handle of future thread.
DESCRIPTION
This function will create new thread to handle the incoming
connection. If there are idle cached threads one will be used.
'thd' will be pushed into 'threads'.
In single-threaded mode (#define ONE_THREAD) connection will be
handled inside this function.
RETURN VALUE
none
*/
static
void
create_new_thread
(
THD
*
thd
)
{
DBUG_ENTER
(
"create_new_thread"
);
...
...
@@ -3952,11 +3960,12 @@ static void create_new_thread(THD *thd)
thd
->
real_id
=
pthread_self
();
// Keep purify happy
/* Start a new thread to handle connection */
thread_count
++
;
#ifdef ONE_THREAD
if
(
test_flags
&
TEST_NO_THREADS
)
// For debugging under Linux
{
thread_cache_size
=
0
;
// Safety
thread_count
++
;
threads
.
append
(
thd
);
thd
->
real_id
=
pthread_self
();
(
void
)
pthread_mutex_unlock
(
&
LOCK_thread_count
);
...
...
@@ -3965,18 +3974,20 @@ static void create_new_thread(THD *thd)
else
#endif
{
if
(
thread_count
-
delayed_insert_threads
>
max_used_connections
)
max_used_connections
=
thread_count
-
delayed_insert_threads
;
if
(
cached_thread_count
>
wake_thread
)
{
start_cached_thread
(
thd
);
thread_cache
.
append
(
thd
);
wake_thread
++
;
pthread_cond_signal
(
&
COND_thread_cache
);
}
else
{
int
error
;
thread_count
++
;
thread_created
++
;
threads
.
append
(
thd
);
if
(
thread_count
-
delayed_insert_threads
>
max_used_connections
)
max_used_connections
=
thread_count
-
delayed_insert_threads
;
DBUG_PRINT
(
"info"
,((
"creating thread %d"
),
thd
->
thread_id
));
thd
->
connect_time
=
time
(
NULL
);
if
((
error
=
pthread_create
(
&
thd
->
real_id
,
&
connection_attrib
,
...
...
@@ -8047,7 +8058,38 @@ static void create_pid_file()
(
void
)
my_close
(
file
,
MYF
(
0
));
}
sql_perror
(
"Can't start server: can't create PID file"
);
exit
(
1
);
exit
(
1
);
}
/* Clear most status variables */
void
refresh_status
(
THD
*
thd
)
{
pthread_mutex_lock
(
&
LOCK_status
);
/* We must update the global status before cleaning up the thread */
add_to_status
(
&
global_status_var
,
&
thd
->
status_var
);
bzero
((
char
*
)
&
thd
->
status_var
,
sizeof
(
thd
->
status_var
));
for
(
SHOW_VAR
*
ptr
=
status_vars
;
ptr
->
name
;
ptr
++
)
{
/* Note that SHOW_LONG_NOFLUSH variables are not reset */
if
(
ptr
->
type
==
SHOW_LONG
)
*
(
ulong
*
)
ptr
->
value
=
0
;
}
/* Reset the counters of all key caches (default and named). */
process_key_caches
(
reset_key_cache_counters
);
pthread_mutex_unlock
(
&
LOCK_status
);
/*
Set max_used_connections to the number of currently open
connections. Lock LOCK_thread_count out of LOCK_status to avoid
deadlocks. Status reset becomes not atomic, but status data is
not exact anyway.
*/
pthread_mutex_lock
(
&
LOCK_thread_count
);
max_used_connections
=
thread_count
-
delayed_insert_threads
;
pthread_mutex_unlock
(
&
LOCK_thread_count
);
}
...
...
sql/sp_head.cc
View file @
3bf0a8e0
...
...
@@ -1229,7 +1229,7 @@ sp_head::execute_function(THD *thd, Item **argp, uint argcount,
DBUG_PRINT
(
"info"
,
(
"function %s"
,
m_name
.
str
));
LINT_INIT
(
binlog_save_options
);
params
=
m_pcont
->
context_pvars
();
params
=
m_pcont
->
context_var_count
();
/*
Check that the function is called with all specified arguments.
...
...
@@ -1412,7 +1412,7 @@ bool
sp_head
::
execute_procedure
(
THD
*
thd
,
List
<
Item
>
*
args
)
{
bool
err_status
=
FALSE
;
uint
params
=
m_pcont
->
context_
pvars
();
uint
params
=
m_pcont
->
context_
var_count
();
sp_rcontext
*
save_spcont
,
*
octx
;
sp_rcontext
*
nctx
=
NULL
;
bool
save_enable_slow_log
=
false
;
...
...
@@ -1466,15 +1466,15 @@ sp_head::execute_procedure(THD *thd, List<Item> *args)
for
(
uint
i
=
0
;
i
<
params
;
i
++
)
{
Item
*
arg_item
=
it_args
++
;
sp_
pvar_t
*
pvar
=
m_pcont
->
find_pvar
(
i
);
sp_
variable_t
*
spvar
=
m_pcont
->
find_variable
(
i
);
if
(
!
arg_item
)
break
;
if
(
!
pvar
)
if
(
!
s
pvar
)
continue
;
if
(
pvar
->
mode
!=
sp_param_in
)
if
(
s
pvar
->
mode
!=
sp_param_in
)
{
if
(
!
arg_item
->
is_splocal
()
&&
!
item_is_user_var
(
arg_item
))
{
...
...
@@ -1484,7 +1484,7 @@ sp_head::execute_procedure(THD *thd, List<Item> *args)
}
}
if
(
pvar
->
mode
==
sp_param_out
)
if
(
s
pvar
->
mode
==
sp_param_out
)
{
Item_null
*
null_item
=
new
Item_null
();
...
...
@@ -1560,9 +1560,9 @@ sp_head::execute_procedure(THD *thd, List<Item> *args)
if
(
!
arg_item
)
break
;
sp_
pvar_t
*
pvar
=
m_pcont
->
find_pvar
(
i
);
sp_
variable_t
*
spvar
=
m_pcont
->
find_variable
(
i
);
if
(
pvar
->
mode
==
sp_param_in
)
if
(
s
pvar
->
mode
==
sp_param_in
)
continue
;
if
(
arg_item
->
is_splocal
())
...
...
@@ -2432,7 +2432,7 @@ sp_instr_set::print(String *str)
{
/* set name@offset ... */
int
rsrv
=
SP_INSTR_UINT_MAXLEN
+
6
;
sp_
pvar_t
*
var
=
m_ctx
->
find_pvar
(
m_offset
);
sp_
variable_t
*
var
=
m_ctx
->
find_variable
(
m_offset
);
/* 'var' should always be non-null, but just in case... */
if
(
var
)
...
...
@@ -3048,8 +3048,8 @@ sp_instr_cfetch::execute(THD *thd, uint *nextp)
void
sp_instr_cfetch
::
print
(
String
*
str
)
{
List_iterator_fast
<
struct
sp_
pvar
>
li
(
m_varlist
);
sp_
pvar
_t
*
pv
;
List_iterator_fast
<
struct
sp_
variable
>
li
(
m_varlist
);
sp_
variable
_t
*
pv
;
LEX_STRING
n
;
my_bool
found
=
m_ctx
->
find_cursor
(
m_cursor
,
&
n
);
/* cfetch name@offset vars... */
...
...
sql/sp_head.h
View file @
3bf0a8e0
...
...
@@ -44,7 +44,7 @@ class sp_instr;
class
sp_instr_opt_meta
;
class
sp_instr_jump_if_not
;
struct
sp_cond_type
;
struct
sp_
pvar
;
struct
sp_
variable
;
class
sp_name
:
public
Sql_alloc
{
...
...
@@ -1075,7 +1075,7 @@ class sp_instr_cfetch : public sp_instr
virtual
void
print
(
String
*
str
);
void
add_to_varlist
(
struct
sp_
pvar
*
var
)
void
add_to_varlist
(
struct
sp_
variable
*
var
)
{
m_varlist
.
push_back
(
var
);
}
...
...
@@ -1083,7 +1083,7 @@ class sp_instr_cfetch : public sp_instr
private:
uint
m_cursor
;
List
<
struct
sp_
pvar
>
m_varlist
;
List
<
struct
sp_
variable
>
m_varlist
;
};
// class sp_instr_cfetch : public sp_instr
...
...
sql/sp_pcontext.cc
View file @
3bf0a8e0
This diff is collapsed.
Click to expand it.
sql/sp_pcontext.h
View file @
3bf0a8e0
...
...
@@ -29,22 +29,23 @@ typedef enum
sp_param_inout
}
sp_param_mode_t
;
typedef
struct
sp_
pvar
typedef
struct
sp_
variable
{
LEX_STRING
name
;
enum
enum_field_types
type
;
sp_param_mode_t
mode
;
/*
offset -- basically, this is an index of variable in the scope of root
parsing context. This means, that all variables in a stored routine
have distinct indexes/offsets.
offset -- this the index to the variable's value in the runtime frame.
This is calculated during parsing and used when creating sp_instr_set
instructions and Item_splocal items.
I.e. values are set/referred by array indexing in runtime.
*/
uint
offset
;
Item
*
dflt
;
create_field
field_def
;
}
sp_
pvar
_t
;
}
sp_
variable
_t
;
#define SP_LAB_REF 0 // Unresolved reference (for goto)
...
...
@@ -76,9 +77,10 @@ typedef struct sp_cond_type
uint
mysqlerr
;
}
sp_cond_type_t
;
/* Sanity check for SQLSTATEs. Will not check if it's really an existing
* state (there are just too many), but will check length bad characters.
*/
/*
Sanity check for SQLSTATEs. Will not check if it's really an existing
state (there are just too many), but will check length bad characters.
*/
extern
bool
sp_cond_check
(
LEX_STRING
*
sqlstate
);
...
...
@@ -90,7 +92,17 @@ typedef struct sp_cond
/*
This seems to be an "SP parsing context" or something.
The parse-time context, used to keep track on declared variables/parameters,
conditions, handlers, cursors and labels, during parsing.
sp_contexts are organized as a tree, with one object for each begin-end
block, plus a root-context for the parameters.
This is used during parsing for looking up defined names (e.g. declared
variables and visible labels), for error checking, and to calculate offsets
to be used at runtime. (During execution variable values, active handlers
and cursors, etc, are referred to by an index in a stack.)
The pcontext tree is also kept during execution and is used for error
checking (e.g. correct number of parameters), and in the future, used by
the debugger.
*/
class
sp_pcontext
:
public
Sql_alloc
...
...
@@ -134,50 +146,64 @@ class sp_pcontext : public Sql_alloc
// Parameters and variables
//
/*
The maximum number of variables used in this and all child contexts
In the root, this gives us the number of slots needed for variables
during execution.
*/
inline
uint
total_pvars
()
max_var_index
()
{
return
m_
total_pvars
;
return
m_
max_var_index
;
}
/*
The current number of variables used in the parents (from the root),
including this context.
*/
inline
uint
current_
pvars
()
current_
var_count
()
{
return
m_
poffset
+
m_pvar
.
elements
;
return
m_
var_offset
+
m_vars
.
elements
;
}
/* The number of variables in this context alone */
inline
uint
context_
pvars
()
context_
var_count
()
{
return
m_
pvar
.
elements
;
return
m_
vars
.
elements
;
}
/* Map index in this pcontext to runtime offset */
inline
uint
pvar_context2index
(
uint
i
)
var_context2runtime
(
uint
i
)
{
return
m_
p
offset
+
i
;
return
m_
var_
offset
+
i
;
}
/* Set type of variable. 'i' is the offset from the top */
inline
void
set_type
(
uint
i
,
enum
enum_field_types
type
)
{
sp_
pvar_t
*
p
=
find_pvar
(
i
);
sp_
variable_t
*
p
=
find_variable
(
i
);
if
(
p
)
p
->
type
=
type
;
}
/* Set default value of variable. 'i' is the offset from the top */
inline
void
set_default
(
uint
i
,
Item
*
it
)
{
sp_
pvar_t
*
p
=
find_pvar
(
i
);
sp_
variable_t
*
p
=
find_variable
(
i
);
if
(
p
)
p
->
dflt
=
it
;
}
sp_pvar_t
*
push_pvar
(
LEX_STRING
*
name
,
enum
enum_field_types
type
,
sp_param_mode_t
mode
);
sp_variable_t
*
push_variable
(
LEX_STRING
*
name
,
enum
enum_field_types
type
,
sp_param_mode_t
mode
);
/*
Retrieve definitions of fields from the current context and its
...
...
@@ -187,12 +213,12 @@ class sp_pcontext : public Sql_alloc
retrieve_field_definitions
(
List
<
create_field
>
*
field_def_lst
);
// Find by name
sp_
pvar
_t
*
find_
pvar
(
LEX_STRING
*
name
,
my_bool
scoped
=
0
);
sp_
variable
_t
*
find_
variable
(
LEX_STRING
*
name
,
my_bool
scoped
=
0
);
// Find by offset
sp_
pvar
_t
*
find_
pvar
(
uint
offset
);
// Find by offset
(from the top)
sp_
variable
_t
*
find_
variable
(
uint
offset
);
/*
Set the current scope boundary (for default values).
...
...
@@ -280,7 +306,7 @@ class sp_pcontext : public Sql_alloc
pop_cond
(
uint
num
)
{
while
(
num
--
)
pop_dynamic
(
&
m_cond
);
pop_dynamic
(
&
m_cond
s
);
}
sp_cond_type_t
*
...
...
@@ -293,22 +319,22 @@ class sp_pcontext : public Sql_alloc
inline
void
push_handler
(
sp_cond_type_t
*
cond
)
{
insert_dynamic
(
&
m_handler
,
(
gptr
)
&
cond
);
insert_dynamic
(
&
m_handler
s
,
(
gptr
)
&
cond
);
}
bool
find_handler
(
sp_cond_type
*
cond
);
inline
uint
max_handler
s
()
max_handler
_index
()
{
return
m_
hsubsize
+
m
_handlers
;
return
m_
max_handler_index
+
m_context
_handlers
;
}
inline
void
add_handlers
(
uint
n
)
{
m_handlers
+=
n
;
m_
context_
handlers
+=
n
;
}
//
...
...
@@ -326,51 +352,51 @@ class sp_pcontext : public Sql_alloc
find_cursor
(
uint
offset
,
LEX_STRING
*
n
);
inline
uint
max_cursor
s
()
max_cursor
_index
()
{
return
m_
csubsize
+
m_cursor
.
elements
;
return
m_
max_cursor_index
+
m_cursors
.
elements
;
}
inline
uint
current_cursor
s
()
current_cursor
_count
()
{
return
m_c
offset
+
m_cursor
.
elements
;
return
m_c
ursor_offset
+
m_cursors
.
elements
;
}
protected:
/*
m_
total_pvars
-- number of variables (including all types of arguments)
m_
max_var_index
-- number of variables (including all types of arguments)
in this context including all children contexts.
m_
total_pvars >= m_pvar
.elements.
m_
max_var_index >= m_vars
.elements.
m_
total_pvars
of the root parsing context contains number of all
m_
max_var_index
of the root parsing context contains number of all
variables (including arguments) in all enclosed contexts.
*/
uint
m_
total_pvars
;
uint
m_
max_var_index
;
// The maximum sub context's framesizes
uint
m_
csubsize
;
uint
m_
hsubsize
;
uint
m_
handlers
;
// No. of handlers in this context
uint
m_
max_cursor_index
;
uint
m_
max_handler_index
;
uint
m_
context_handlers
;
// No. of handlers in this context
private:
sp_pcontext
*
m_parent
;
// Parent context
/*
m_
poffset -- basically,
this is an index of the first variable in this
parsing context.
m_
var_offset --
this is an index of the first variable in this
parsing context.
m_
p
offset is 0 for root context.
m_
var_
offset is 0 for root context.
Since now each variable is stored in separate place, no reuse is done,
so m_
p
offset is different for all enclosed contexts.
so m_
var_
offset is different for all enclosed contexts.
*/
uint
m_
p
offset
;
uint
m_
var_
offset
;
uint
m_coffset
;
// Cursor offset for this context
uint
m_c
ursor_
offset
;
// Cursor offset for this context
/*
Boundary for finding variables in this context. This is the number
...
...
@@ -382,11 +408,11 @@ class sp_pcontext : public Sql_alloc
int
m_num_case_exprs
;
DYNAMIC_ARRAY
m_
pvar
;
// Parameters/variables
DYNAMIC_ARRAY
m_
vars
;
// Parameters/variables
DYNAMIC_ARRAY
m_case_expr_id_lst
;
/* Stack of CASE expression ids. */
DYNAMIC_ARRAY
m_cond
;
// Conditions
DYNAMIC_ARRAY
m_cursor
;
// Cursors
DYNAMIC_ARRAY
m_handler
;
// Handlers, for checking of
duplicates
DYNAMIC_ARRAY
m_cond
s
;
// Conditions
DYNAMIC_ARRAY
m_cursor
s
;
// Cursors
DYNAMIC_ARRAY
m_handler
s
;
// Handlers, for checking for
duplicates
List
<
sp_label_t
>
m_label
;
// The label list
...
...
sql/sp_rcontext.cc
View file @
3bf0a8e0
...
...
@@ -73,16 +73,16 @@ bool sp_rcontext::init(THD *thd)
return
!
(
m_handler
=
(
sp_handler_t
*
)
thd
->
alloc
(
m_root_parsing_ctx
->
max_handler
s
()
*
(
sp_handler_t
*
)
thd
->
alloc
(
m_root_parsing_ctx
->
max_handler
_index
()
*
sizeof
(
sp_handler_t
)))
||
!
(
m_hstack
=
(
uint
*
)
thd
->
alloc
(
m_root_parsing_ctx
->
max_handler
s
()
*
(
uint
*
)
thd
->
alloc
(
m_root_parsing_ctx
->
max_handler
_index
()
*
sizeof
(
uint
)))
||
!
(
m_in_handler
=
(
uint
*
)
thd
->
alloc
(
m_root_parsing_ctx
->
max_handler
s
()
*
(
uint
*
)
thd
->
alloc
(
m_root_parsing_ctx
->
max_handler
_index
()
*
sizeof
(
uint
)))
||
!
(
m_cstack
=
(
sp_cursor
**
)
thd
->
alloc
(
m_root_parsing_ctx
->
max_cursor
s
()
*
(
sp_cursor
**
)
thd
->
alloc
(
m_root_parsing_ctx
->
max_cursor
_index
()
*
sizeof
(
sp_cursor
*
)))
||
!
(
m_case_expr_holders
=
(
Item_cache
**
)
thd
->
calloc
(
m_root_parsing_ctx
->
get_num_case_exprs
()
*
...
...
@@ -105,12 +105,12 @@ sp_rcontext::init_var_table(THD *thd)
{
List
<
create_field
>
field_def_lst
;
if
(
!
m_root_parsing_ctx
->
total_pvars
())
if
(
!
m_root_parsing_ctx
->
max_var_index
())
return
FALSE
;
m_root_parsing_ctx
->
retrieve_field_definitions
(
&
field_def_lst
);
DBUG_ASSERT
(
field_def_lst
.
elements
==
m_root_parsing_ctx
->
total_pvars
());
DBUG_ASSERT
(
field_def_lst
.
elements
==
m_root_parsing_ctx
->
max_var_index
());
if
(
!
(
m_var_table
=
create_virtual_tmp_table
(
thd
,
field_def_lst
)))
return
TRUE
;
...
...
@@ -134,7 +134,7 @@ bool
sp_rcontext
::
init_var_items
()
{
uint
idx
;
uint
num_vars
=
m_root_parsing_ctx
->
total_pvars
();
uint
num_vars
=
m_root_parsing_ctx
->
max_var_index
();
if
(
!
(
m_var_items
=
(
Item
**
)
sql_alloc
(
num_vars
*
sizeof
(
Item
*
))))
return
TRUE
;
...
...
@@ -381,7 +381,7 @@ sp_cursor::destroy()
int
sp_cursor
::
fetch
(
THD
*
thd
,
List
<
struct
sp_
pvar
>
*
vars
)
sp_cursor
::
fetch
(
THD
*
thd
,
List
<
struct
sp_
variable
>
*
vars
)
{
if
(
!
server_side_cursor
)
{
...
...
@@ -528,9 +528,9 @@ int Select_fetch_into_spvars::prepare(List<Item> &fields, SELECT_LEX_UNIT *u)
bool
Select_fetch_into_spvars
::
send_data
(
List
<
Item
>
&
items
)
{
List_iterator_fast
<
struct
sp_
pvar
>
pv
_iter
(
*
spvar_list
);
List_iterator_fast
<
struct
sp_
variable
>
spvar
_iter
(
*
spvar_list
);
List_iterator_fast
<
Item
>
item_iter
(
items
);
sp_
pvar_t
*
pv
;
sp_
variable_t
*
spvar
;
Item
*
item
;
/* Must be ensured by the caller */
...
...
@@ -540,9 +540,9 @@ bool Select_fetch_into_spvars::send_data(List<Item> &items)
Assign the row fetched from a server side cursor to stored
procedure variables.
*/
for
(;
pv
=
pv
_iter
++
,
item
=
item_iter
++
;
)
for
(;
spvar
=
spvar
_iter
++
,
item
=
item_iter
++
;
)
{
if
(
thd
->
spcont
->
set_variable
(
thd
,
pv
->
offset
,
item
))
if
(
thd
->
spcont
->
set_variable
(
thd
,
spvar
->
offset
,
item
))
return
TRUE
;
}
return
FALSE
;
...
...
sql/sp_rcontext.h
View file @
3bf0a8e0
...
...
@@ -24,7 +24,7 @@
struct
sp_cond_type
;
class
sp_cursor
;
struct
sp_
pvar
;
struct
sp_
variable
;
class
sp_lex_keeper
;
class
sp_instr_cpush
;
...
...
@@ -265,12 +265,12 @@ class sp_rcontext : public Sql_alloc
class
Select_fetch_into_spvars
:
public
select_result_interceptor
{
List
<
struct
sp_
pvar
>
*
spvar_list
;
List
<
struct
sp_
variable
>
*
spvar_list
;
uint
field_count
;
public:
Select_fetch_into_spvars
()
{}
/* Remove gcc warning */
uint
get_field_count
()
{
return
field_count
;
}
void
set_spvar_list
(
List
<
struct
sp_
pvar
>
*
vars
)
{
spvar_list
=
vars
;
}
void
set_spvar_list
(
List
<
struct
sp_
variable
>
*
vars
)
{
spvar_list
=
vars
;
}
virtual
bool
send_eof
()
{
return
FALSE
;
}
virtual
bool
send_data
(
List
<
Item
>
&
items
);
...
...
@@ -307,7 +307,7 @@ class sp_cursor : public Sql_alloc
}
int
fetch
(
THD
*
,
List
<
struct
sp_
pvar
>
*
vars
);
fetch
(
THD
*
,
List
<
struct
sp_
variable
>
*
vars
);
inline
sp_instr_cpush
*
get_instr
()
...
...
sql/sql_parse.cc
View file @
3bf0a8e0
...
...
@@ -68,7 +68,6 @@ static void decrease_user_connections(USER_CONN *uc);
static
bool
check_db_used
(
THD
*
thd
,
TABLE_LIST
*
tables
);
static
bool
check_multi_update_lock
(
THD
*
thd
);
static
void
remove_escape
(
char
*
name
);
static
void
refresh_status
(
THD
*
thd
);
const
char
*
any_db
=
"*any*"
;
// Special symbol for check_access
...
...
@@ -6905,26 +6904,6 @@ void kill_one_thread(THD *thd, ulong id, bool only_kill_query)
}
/* Clear most status variables */
static
void
refresh_status
(
THD
*
thd
)
{
pthread_mutex_lock
(
&
LOCK_status
);
/* We must update the global status before cleaning up the thread */
add_to_status
(
&
global_status_var
,
&
thd
->
status_var
);
bzero
((
char
*
)
&
thd
->
status_var
,
sizeof
(
thd
->
status_var
));
for
(
SHOW_VAR
*
ptr
=
status_vars
;
ptr
->
name
;
ptr
++
)
if
(
ptr
->
type
==
SHOW_LONG
)
// note that SHOW_LONG_NOFLUSH variables are not reset
*
(
ulong
*
)
ptr
->
value
=
0
;
/* Reset the counters of all key caches (default and named). */
process_key_caches
(
reset_key_cache_counters
);
pthread_mutex_unlock
(
&
LOCK_status
);
}
/* If pointer is not a null pointer, append filename to it */
bool
append_file_to_dir
(
THD
*
thd
,
const
char
**
filename_ptr
,
...
...
sql/sql_yacc.yy
View file @
3bf0a8e0
...
...
@@ -1819,22 +1819,23 @@ sp_fdparam:
LEX *lex= Lex;
sp_pcontext *spc= lex->spcont;
if (spc->find_
pvar
(&$1, TRUE))
if (spc->find_
variable
(&$1, TRUE))
{
my_error(ER_SP_DUP_PARAM, MYF(0), $1.str);
YYABORT;
}
sp_pvar_t *pvar= spc->push_pvar(&$1, (enum enum_field_types)$3,
sp_param_in);
sp_variable_t *spvar= spc->push_variable(&$1,
(enum enum_field_types)$3,
sp_param_in);
if (lex->sphead->fill_field_definition(YYTHD, lex,
(enum enum_field_types) $3,
&pvar->field_def))
&
s
pvar->field_def))
{
YYABORT;
}
pvar->field_def.field_name=
pvar->name.str;
pvar->field_def.pack_flag |= FIELDFLAG_MAYBE_NULL;
spvar->field_def.field_name= s
pvar->name.str;
s
pvar->field_def.pack_flag |= FIELDFLAG_MAYBE_NULL;
}
;
...
...
@@ -1855,22 +1856,23 @@ sp_pdparam:
LEX *lex= Lex;
sp_pcontext *spc= lex->spcont;
if (spc->find_
pvar
(&$3, TRUE))
if (spc->find_
variable
(&$3, TRUE))
{
my_error(ER_SP_DUP_PARAM, MYF(0), $3.str);
YYABORT;
}
sp_pvar_t *pvar= spc->push_pvar(&$3, (enum enum_field_types)$4,
(sp_param_mode_t)$1);
sp_variable_t *spvar= spc->push_variable(&$3,
(enum enum_field_types)$4,
(sp_param_mode_t)$1);
if (lex->sphead->fill_field_definition(YYTHD, lex,
(enum enum_field_types) $4,
&pvar->field_def))
&
s
pvar->field_def))
{
YYABORT;
}
pvar->field_def.field_name=
pvar->name.str;
pvar->field_def.pack_flag |= FIELDFLAG_MAYBE_NULL;
spvar->field_def.field_name= s
pvar->name.str;
s
pvar->field_def.pack_flag |= FIELDFLAG_MAYBE_NULL;
}
;
...
...
@@ -1934,7 +1936,7 @@ sp_decl:
{
LEX *lex= Lex;
sp_pcontext *pctx= lex->spcont;
uint num_vars= pctx->context_
pvars
();
uint num_vars= pctx->context_
var_count
();
enum enum_field_types var_type= (enum enum_field_types) $4;
Item *dflt_value_item= $5;
create_field *create_field_op;
...
...
@@ -1947,23 +1949,23 @@ sp_decl:
for (uint i = num_vars-$2 ; i < num_vars ; i++)
{
uint var_idx= pctx->
pvar_context2index
(i);
sp_
pvar_t *pvar= pctx->find_pvar
(var_idx);
uint var_idx= pctx->
var_context2runtime
(i);
sp_
variable_t *spvar= pctx->find_variable
(var_idx);
if (!pvar)
if (!
s
pvar)
YYABORT;
pvar->type= var_type;
pvar->dflt= dflt_value_item;
s
pvar->type= var_type;
s
pvar->dflt= dflt_value_item;
if (lex->sphead->fill_field_definition(YYTHD, lex, var_type,
&pvar->field_def))
&
s
pvar->field_def))
{
YYABORT;
}
pvar->field_def.field_name=
pvar->name.str;
pvar->field_def.pack_flag |= FIELDFLAG_MAYBE_NULL;
spvar->field_def.field_name= s
pvar->name.str;
s
pvar->field_def.pack_flag |= FIELDFLAG_MAYBE_NULL;
/* The last instruction is responsible for freeing LEX. */
...
...
@@ -2000,7 +2002,7 @@ sp_decl:
sp_pcontext *ctx= lex->spcont;
sp_instr_hpush_jump *i=
new sp_instr_hpush_jump(sp->instructions(), ctx, $2,
ctx->current_
pvars
());
ctx->current_
var_count
());
sp->add_instr(i);
sp->push_backpatch(i, ctx->push_label((char *)"", 0));
...
...
@@ -2017,7 +2019,7 @@ sp_decl:
if ($2 == SP_HANDLER_CONTINUE)
{
i= new sp_instr_hreturn(sp->instructions(), ctx,
ctx->current_
pvars
());
ctx->current_
var_count
());
sp->add_instr(i);
}
else
...
...
@@ -2048,7 +2050,7 @@ sp_decl:
YYABORT;
}
i= new sp_instr_cpush(sp->instructions(), ctx, $5,
ctx->current_cursor
s
());
ctx->current_cursor
_count
());
sp->add_instr(i);
ctx->push_cursor(&$2);
$$.vars= $$.conds= $$.hndlrs= 0;
...
...
@@ -2203,12 +2205,12 @@ sp_decl_idents:
LEX *lex= Lex;
sp_pcontext *spc= lex->spcont;
if (spc->find_
pvar
(&$1, TRUE))
if (spc->find_
variable
(&$1, TRUE))
{
my_error(ER_SP_DUP_VAR, MYF(0), $1.str);
YYABORT;
}
spc->push_
pvar
(&$1, (enum_field_types)0, sp_param_in);
spc->push_
variable
(&$1, (enum_field_types)0, sp_param_in);
$$= 1;
}
| sp_decl_idents ',' ident
...
...
@@ -2218,12 +2220,12 @@ sp_decl_idents:
LEX *lex= Lex;
sp_pcontext *spc= lex->spcont;
if (spc->find_
pvar
(&$3, TRUE))
if (spc->find_
variable
(&$3, TRUE))
{
my_error(ER_SP_DUP_VAR, MYF(0), $3.str);
YYABORT;
}
spc->push_
pvar
(&$3, (enum_field_types)0, sp_param_in);
spc->push_
variable
(&$3, (enum_field_types)0, sp_param_in);
$$= $1 + 1;
}
;
...
...
@@ -2606,9 +2608,9 @@ sp_fetch_list:
LEX *lex= Lex;
sp_head *sp= lex->sphead;
sp_pcontext *spc= lex->spcont;
sp_
pvar
_t *spv;
sp_
variable
_t *spv;
if (!spc || !(spv = spc->find_
pvar
(&$1)))
if (!spc || !(spv = spc->find_
variable
(&$1)))
{
my_error(ER_SP_UNDECLARED_VAR, MYF(0), $1.str);
YYABORT;
...
...
@@ -2627,9 +2629,9 @@ sp_fetch_list:
LEX *lex= Lex;
sp_head *sp= lex->sphead;
sp_pcontext *spc= lex->spcont;
sp_
pvar
_t *spv;
sp_
variable
_t *spv;
if (!spc || !(spv = spc->find_
pvar
(&$3)))
if (!spc || !(spv = spc->find_
variable
(&$3)))
{
my_error(ER_SP_UNDECLARED_VAR, MYF(0), $3.str);
YYABORT;
...
...
@@ -7534,9 +7536,9 @@ select_var_ident:
| ident_or_text
{
LEX *lex=Lex;
sp_
pvar
_t *t;
sp_
variable
_t *t;
if (!lex->spcont || !(t=lex->spcont->find_
pvar
(&$1)))
if (!lex->spcont || !(t=lex->spcont->find_
variable
(&$1)))
{
my_error(ER_SP_UNDECLARED_VAR, MYF(0), $1.str);
YYABORT;
...
...
@@ -8973,10 +8975,10 @@ order_ident:
simple_ident:
ident
{
sp_
pvar
_t *spv;
sp_
variable
_t *spv;
LEX *lex = Lex;
sp_pcontext *spc = lex->spcont;
if (spc && (spv = spc->find_
pvar
(&$1)))
if (spc && (spv = spc->find_
variable
(&$1)))
{
/* We're compiling a stored procedure and found a variable */
Item_splocal *splocal;
...
...
@@ -9764,7 +9766,7 @@ sys_option_value:
{
/* An SP local variable */
sp_pcontext *ctx= lex->spcont;
sp_
pvar
_t *spv;
sp_
variable
_t *spv;
sp_instr_set *sp_set;
Item *it;
if ($1)
...
...
@@ -9773,7 +9775,7 @@ sys_option_value:
YYABORT;
}
spv= ctx->find_
pvar
(&$2.base_name);
spv= ctx->find_
variable
(&$2.base_name);
if ($4)
it= $4;
...
...
@@ -9822,7 +9824,7 @@ option_value:
names.str= (char *)"names";
names.length= 5;
if (spc && spc->find_
pvar
(&names))
if (spc && spc->find_
variable
(&names))
my_error(ER_SP_BAD_VAR_SHADOW, MYF(0), names.str);
else
yyerror(ER(ER_SYNTAX_ERROR));
...
...
@@ -9852,7 +9854,7 @@ option_value:
pw.str= (char *)"password";
pw.length= 8;
if (spc && spc->find_
pvar
(&pw))
if (spc && spc->find_
variable
(&pw))
{
my_error(ER_SP_BAD_VAR_SHADOW, MYF(0), pw.str);
YYABORT;
...
...
@@ -9874,10 +9876,10 @@ internal_variable_name:
{
LEX *lex= Lex;
sp_pcontext *spc= lex->spcont;
sp_
pvar
_t *spv;
sp_
variable
_t *spv;
/* We have to lookup here since local vars can shadow sysvars */
if (!spc || !(spv = spc->find_
pvar
(&$1)))
if (!spc || !(spv = spc->find_
variable
(&$1)))
{
/* Not an SP local variable */
sys_var *tmp=find_sys_var($1.str, $1.length);
...
...
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