Skip to content

Commit 523ef2a

Browse files
committed
Merge 11.5 into 11.6
2 parents c175f49 + 06a7352 commit 523ef2a

File tree

7 files changed

+254
-209
lines changed

7 files changed

+254
-209
lines changed

include/m_ctype.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,6 +1932,52 @@ my_strcasecmp_latin1(const char *a, const char *b)
19321932
int my_wc_mb_utf8mb4_bmp_only(CHARSET_INFO *cs, my_wc_t wc, uchar *r,
19331933
uchar *e);
19341934

1935+
#ifdef __cplusplus
1936+
1937+
class String_copy_status: protected MY_STRCOPY_STATUS
1938+
{
1939+
public:
1940+
const char *source_end_pos() const
1941+
{ return m_source_end_pos; }
1942+
const char *well_formed_error_pos() const
1943+
{ return m_well_formed_error_pos; }
1944+
};
1945+
1946+
1947+
class Well_formed_prefix_status: public String_copy_status
1948+
{
1949+
public:
1950+
Well_formed_prefix_status(CHARSET_INFO *cs,
1951+
const char *str, const char *end, size_t nchars)
1952+
{ cs->well_formed_char_length(str, end, nchars, this); }
1953+
};
1954+
1955+
1956+
class Well_formed_prefix: public Well_formed_prefix_status
1957+
{
1958+
const char *m_str; // The beginning of the string
1959+
public:
1960+
Well_formed_prefix(CHARSET_INFO *cs, const char *str, const char *end,
1961+
size_t nchars)
1962+
:Well_formed_prefix_status(cs, str, end, nchars), m_str(str)
1963+
{ }
1964+
Well_formed_prefix(CHARSET_INFO *cs, const char *str, size_t length,
1965+
size_t nchars)
1966+
:Well_formed_prefix_status(cs, str, str + length, nchars), m_str(str)
1967+
{ }
1968+
Well_formed_prefix(CHARSET_INFO *cs, const char *str, size_t length)
1969+
:Well_formed_prefix_status(cs, str, str + length, length), m_str(str)
1970+
{ }
1971+
Well_formed_prefix(CHARSET_INFO *cs, LEX_CSTRING str, size_t nchars)
1972+
:Well_formed_prefix_status(cs, str.str, str.str + str.length, nchars),
1973+
m_str(str.str)
1974+
{ }
1975+
size_t length() const { return m_source_end_pos - m_str; }
1976+
};
1977+
1978+
#endif /* __cplusplus */
1979+
1980+
19351981
#ifdef__cplusplus
19361982
}
19371983
#endif

mysql-test/main/tmp_table_count-7586.result

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ a
77
1
88
2
99
3
10-
show status like '%Created_tmp%';
10+
show status like '%Created_tmp_tables%';
1111
Variable_name Value
12-
Created_tmp_disk_tables 0
13-
Created_tmp_files 0
1412
Created_tmp_tables 0
1513
explain select * from v2;
1614
id select_type table type possible_keys key key_len ref rows Extra
@@ -20,10 +18,8 @@ a
2018
1
2119
2
2220
3
23-
show status like '%Created_tmp%';
21+
show status like '%Created_tmp_tables%';
2422
Variable_name Value
25-
Created_tmp_disk_tables 0
26-
Created_tmp_files 0
2723
Created_tmp_tables 0
2824
explain select * from (select * from t2) T1;
2925
id select_type table type possible_keys key key_len ref rows Extra
@@ -46,10 +42,8 @@ CREATE TABLE t3 SELECT * FROM t1 WHERE a IN (SELECT * FROM t2 GROUP BY a HAVING
4642
select sum(created_tmp_tables) from performance_schema.events_statements_history_long;
4743
sum(created_tmp_tables)
4844
2
49-
show status like '%Created_tmp%';
45+
show status like '%Created_tmp_tables%';
5046
Variable_name Value
51-
Created_tmp_disk_tables 0
52-
Created_tmp_files 0
5347
Created_tmp_tables 2
5448
drop table t3;
5549
set @@optimizer_switch="firstmatch=off";
@@ -65,10 +59,8 @@ CREATE TABLE t3 SELECT * FROM t1 WHERE a IN (SELECT * FROM t2 GROUP BY a);
6559
select sum(created_tmp_tables) from performance_schema.events_statements_history_long;
6660
sum(created_tmp_tables)
6761
1
68-
show status like '%Created_tmp%';
62+
show status like '%Created_tmp_tables%';
6963
Variable_name Value
70-
Created_tmp_disk_tables 0
71-
Created_tmp_files 0
7264
Created_tmp_tables 1
7365
set @@optimizer_switch=default;
7466
drop table t1,t2,t3;
@@ -78,8 +70,6 @@ flush status;
7870
select sum(created_tmp_tables) from performance_schema.events_statements_history_long;
7971
sum(created_tmp_tables)
8072
0
81-
show status like '%Created_tmp%';
73+
show status like '%Created_tmp_tables%';
8274
Variable_name Value
83-
Created_tmp_disk_tables 0
84-
Created_tmp_files 0
8575
Created_tmp_tables 0

mysql-test/main/tmp_table_count-7586.test

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ create view v2 as select a from t2;
1414
flush status;
1515
select * from v2;
1616
--disable_ps_protocol
17-
show status like '%Created_tmp%';
17+
show status like '%Created_tmp_tables%';
1818
--enable_ps_protocol
1919

2020
explain select * from v2;
2121

2222
select * from (select * from t2) T1;
2323
--disable_ps_protocol
24-
show status like '%Created_tmp%';
24+
show status like '%Created_tmp_tables%';
2525
--enable_ps_protocol
2626

2727
explain select * from (select * from t2) T1;
@@ -44,7 +44,7 @@ flush status;
4444
CREATE TABLE t3 SELECT * FROM t1 WHERE a IN (SELECT * FROM t2 GROUP BY a HAVING a > 1);
4545
--echo # Performance schema should be the same as "Created_tmp_tables" variable below
4646
select sum(created_tmp_tables) from performance_schema.events_statements_history_long;
47-
show status like '%Created_tmp%';
47+
show status like '%Created_tmp_tables%';
4848
drop table t3;
4949

5050
set @@optimizer_switch="firstmatch=off";
@@ -54,7 +54,7 @@ flush status;
5454
CREATE TABLE t3 SELECT * FROM t1 WHERE a IN (SELECT * FROM t2 GROUP BY a);
5555
--echo # Performance schema should be the same as "Created_tmp_tables" variable below
5656
select sum(created_tmp_tables) from performance_schema.events_statements_history_long;
57-
show status like '%Created_tmp%';
57+
show status like '%Created_tmp_tables%';
5858
set @@optimizer_switch=default;
5959

6060
drop table t1,t2,t3;
@@ -63,4 +63,4 @@ truncate table performance_schema.events_statements_history_long;
6363
flush status;
6464
--echo # Performance schema should be the same as "Created_tmp_tables" variable below
6565
select sum(created_tmp_tables) from performance_schema.events_statements_history_long;
66-
show status like '%Created_tmp%';
66+
show status like '%Created_tmp_tables%';

sql/lex_ident_cli.h

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/* Copyright (c) 2000, 2019, Oracle and/or its affiliates.
2+
Copyright (c) 2010, 2024, MariaDB Corporation.
3+
4+
This program is free software; you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation; version 2 of the License.
7+
8+
This program is distributed in the hope that it will be useful,
9+
but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
GNU General Public License for more details.
12+
13+
You should have received a copy of the GNU General Public License
14+
along with this program; if not, write to the Free Software
15+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
16+
17+
18+
#ifndef LEX_IDENT_CLI
19+
#define LEX_IDENT_CLI
20+
21+
#include "my_global.h"
22+
#include "m_ctype.h"
23+
24+
25+
/**
26+
A string with metadata. Usually points to a string in the client
27+
character set, but unlike Lex_ident_cli_st (see below) it does not
28+
necessarily point to a query fragment. It can also point to memory
29+
of other kinds (e.g. an additional THD allocated memory buffer
30+
not overlapping with the current query text).
31+
32+
We'll add more flags here eventually, to know if the string has, e.g.:
33+
- multi-byte characters
34+
- bad byte sequences
35+
- backslash escapes: 'a\nb'
36+
and reuse the original query fragments instead of making the string
37+
copy too early, in Lex_input_stream::get_text().
38+
This will allow to avoid unnecessary copying, as well as
39+
create more optimal Item types in sql_yacc.yy
40+
*/
41+
struct Lex_string_with_metadata_st: public LEX_CSTRING
42+
{
43+
private:
44+
bool m_is_8bit; // True if the string has 8bit characters
45+
char m_quote; // Quote character, or 0 if not quoted
46+
public:
47+
void set_8bit(bool is_8bit) { m_is_8bit= is_8bit; }
48+
void set_metadata(bool is_8bit, char quote)
49+
{
50+
m_is_8bit= is_8bit;
51+
m_quote= quote;
52+
}
53+
void set(const char *s, size_t len, bool is_8bit, char quote)
54+
{
55+
str= s;
56+
length= len;
57+
set_metadata(is_8bit, quote);
58+
}
59+
void set(const LEX_CSTRING *s, bool is_8bit, char quote)
60+
{
61+
((LEX_CSTRING &)*this)= *s;
62+
set_metadata(is_8bit, quote);
63+
}
64+
bool is_8bit() const { return m_is_8bit; }
65+
bool is_quoted() const { return m_quote != '\0'; }
66+
char quote() const { return m_quote; }
67+
// Get string repertoire by the 8-bit flag and the character set
68+
my_repertoire_t repertoire(CHARSET_INFO *cs) const
69+
{
70+
return !m_is_8bit && my_charset_is_ascii_based(cs) ?
71+
MY_REPERTOIRE_ASCII : MY_REPERTOIRE_UNICODE30;
72+
}
73+
// Get string repertoire by the 8-bit flag, for ASCII-based character sets
74+
my_repertoire_t repertoire() const
75+
{
76+
return !m_is_8bit ? MY_REPERTOIRE_ASCII : MY_REPERTOIRE_UNICODE30;
77+
}
78+
};
79+
80+
81+
/*
82+
Used to store identifiers in the client character set.
83+
Points to a query fragment.
84+
*/
85+
struct Lex_ident_cli_st: public Lex_string_with_metadata_st
86+
{
87+
public:
88+
void set_keyword(const char *s, size_t len)
89+
{
90+
set(s, len, false, '\0');
91+
}
92+
void set_ident(const char *s, size_t len, bool is_8bit)
93+
{
94+
set(s, len, is_8bit, '\0');
95+
}
96+
void set_ident_quoted(const char *s, size_t len, bool is_8bit, char quote)
97+
{
98+
set(s, len, is_8bit, quote);
99+
}
100+
void set_unquoted(const LEX_CSTRING *s, bool is_8bit)
101+
{
102+
set(s, is_8bit, '\0');
103+
}
104+
const char *pos() const { return str - is_quoted(); }
105+
const char *end() const { return str + length + is_quoted(); }
106+
};
107+
108+
109+
class Lex_ident_cli: public Lex_ident_cli_st
110+
{
111+
public:
112+
Lex_ident_cli(const LEX_CSTRING *s, bool is_8bit)
113+
{
114+
set_unquoted(s, is_8bit);
115+
}
116+
Lex_ident_cli(const char *s, size_t len)
117+
{
118+
set_ident(s, len, false);
119+
}
120+
};
121+
122+
#endif // LEX_IDENT_CLI

sql/lex_ident_sys.h

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/* Copyright (c) 2000, 2019, Oracle and/or its affiliates.
2+
Copyright (c) 2010, 2024, MariaDB Corporation.
3+
4+
This program is free software; you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation; version 2 of the License.
7+
8+
This program is distributed in the hope that it will be useful,
9+
but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
GNU General Public License for more details.
12+
13+
You should have received a copy of the GNU General Public License
14+
along with this program; if not, write to the Free Software
15+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
16+
17+
18+
#ifndef LEX_IDENT_SYS
19+
#define LEX_IDENT_SYS
20+
21+
#include "lex_ident_cli.h"
22+
#include "sql_alloc.h"
23+
24+
extern "C" MYSQL_PLUGIN_IMPORT CHARSET_INFO *system_charset_info;
25+
26+
struct Lex_ident_sys_st: public LEX_CSTRING, Sql_alloc
27+
{
28+
public:
29+
bool copy_ident_cli(const THD *thd, const Lex_ident_cli_st *str);
30+
bool copy_keyword(const THD *thd, const Lex_ident_cli_st *str);
31+
bool copy_sys(const THD *thd, const LEX_CSTRING *str);
32+
bool convert(const THD *thd, const LEX_CSTRING *str, CHARSET_INFO *cs);
33+
bool copy_or_convert(const THD *thd, const Lex_ident_cli_st *str,
34+
CHARSET_INFO *cs);
35+
bool is_null() const { return str == NULL; }
36+
bool to_size_number(ulonglong *to) const;
37+
void set_valid_utf8(const LEX_CSTRING *name)
38+
{
39+
DBUG_ASSERT(Well_formed_prefix(system_charset_info, name->str,
40+
name->length).length() == name->length);
41+
str= name->str ; length= name->length;
42+
}
43+
};
44+
45+
46+
class Lex_ident_sys: public Lex_ident_sys_st
47+
{
48+
public:
49+
Lex_ident_sys(const THD *thd, const Lex_ident_cli_st *str)
50+
{
51+
if (copy_ident_cli(thd, str))
52+
*this= Lex_ident_sys();
53+
}
54+
Lex_ident_sys()
55+
{
56+
((LEX_CSTRING &) *this)= {nullptr, 0};
57+
}
58+
Lex_ident_sys(const char *name, size_t length)
59+
{
60+
LEX_CSTRING tmp= {name, length};
61+
set_valid_utf8(&tmp);
62+
}
63+
Lex_ident_sys(const THD *thd, const LEX_CSTRING *str)
64+
{
65+
set_valid_utf8(str);
66+
}
67+
Lex_ident_sys & operator=(const Lex_ident_sys_st &name)
68+
{
69+
Lex_ident_sys_st::operator=(name);
70+
return *this;
71+
}
72+
};
73+
74+
75+
#endif // LEX_IDENT_SYS

0 commit comments

Comments
 (0)