Skip to content

Commit 7d5caca

Browse files
committed
Merge branch 'mysql-8.0' into mysql-trunk
2 parents c65c633 + fd53121 commit 7d5caca

10 files changed

+107
-60
lines changed

mysql-test/r/parser.result

+15
Original file line numberDiff line numberDiff line change
@@ -2651,3 +2651,18 @@ WITH cte AS (SELECT 0 /*! ) */ SELECT * FROM cte a, cte b;
26512651
WITH cte AS /*! ( */ SELECT 0) SELECT * FROM cte a, cte b;
26522652
0 0
26532653
0 0
2654+
#
2655+
# Bug#30528450: SPECIAL SYMBOL NAMED COLUMN NOT HONORED IN A SELECT
2656+
#
2657+
CREATE TABLE t1 (c1 INT, `*` INT, c3 INT);
2658+
INSERT INTO t1 VALUES (1, 2, 3);
2659+
SELECT `*` FROM t1;
2660+
*
2661+
2
2662+
SELECT t1.`*`, t1.* FROM t1;
2663+
* c1 * c3
2664+
2 1 2 3
2665+
SELECT test.t1.`*`, test.t1.* FROM t1;
2666+
* c1 * c3
2667+
2 1 2 3
2668+
DROP TABLE t1;

mysql-test/t/parser.test

+13
Original file line numberDiff line numberDiff line change
@@ -2549,3 +2549,16 @@ SELECT 1 UNION (SELECT 1 FROM DUAL INTO @var);
25492549

25502550
WITH cte AS (SELECT 0 /*! ) */ SELECT * FROM cte a, cte b;
25512551
WITH cte AS /*! ( */ SELECT 0) SELECT * FROM cte a, cte b;
2552+
2553+
--echo #
2554+
--echo # Bug#30528450: SPECIAL SYMBOL NAMED COLUMN NOT HONORED IN A SELECT
2555+
--echo #
2556+
2557+
CREATE TABLE t1 (c1 INT, `*` INT, c3 INT);
2558+
INSERT INTO t1 VALUES (1, 2, 3);
2559+
2560+
SELECT `*` FROM t1;
2561+
SELECT t1.`*`, t1.* FROM t1;
2562+
SELECT test.t1.`*`, test.t1.* FROM t1;
2563+
2564+
DROP TABLE t1;

sql/dd/info_schema/show_query_builder.cc

+2-4
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,8 @@ bool Select_lex_builder::add_to_select_item_list(Item *expr) {
7373

7474
// Add item representing star in "SELECT '*' ...".
7575
bool Select_lex_builder::add_star_select_item() {
76-
const LEX_CSTRING star = {STRING_WITH_LEN("*")};
77-
78-
PTI_simple_ident_ident *ident_star =
79-
new (m_thd->mem_root) PTI_simple_ident_ident(*m_pos, star);
76+
Item_asterisk *ident_star =
77+
new (m_thd->mem_root) Item_asterisk(*m_pos, nullptr, nullptr);
8078
if (ident_star == nullptr) return true;
8179

8280
return add_to_select_item_list(ident_star);

sql/item.cc

+13-4
Original file line numberDiff line numberDiff line change
@@ -2513,10 +2513,6 @@ bool Item_field::itemize(Parse_context *pc, Item **res) {
25132513
if (super::itemize(pc, res)) return true;
25142514
SELECT_LEX *const select = pc->select;
25152515
if (select->parsing_place != CTX_HAVING) select->select_n_where_fields++;
2516-
2517-
if (select->parsing_place == CTX_SELECT_LIST && field_name &&
2518-
field_name[0] == '*' && field_name[1] == 0)
2519-
select->with_wild++;
25202516
return false;
25212517
}
25222518

@@ -10333,3 +10329,16 @@ Item_field *FindEqualField(Item_field *item_field, table_map reachable_tables) {
1033310329

1033410330
return item_field;
1033510331
}
10332+
10333+
bool Item_asterisk::itemize(Parse_context *pc, Item **res) {
10334+
DBUG_ASSERT(pc->select->parsing_place == CTX_SELECT_LIST);
10335+
10336+
if (skip_itemize(res)) {
10337+
return false;
10338+
}
10339+
if (super::itemize(pc, res)) {
10340+
return true;
10341+
}
10342+
pc->select->with_wild++;
10343+
return false;
10344+
}

sql/item.h

+42
Original file line numberDiff line numberDiff line change
@@ -4080,6 +4080,48 @@ class Item_field : public Item_ident {
40804080

40814081
bool replace_field_processor(uchar *arg) override;
40824082
bool strip_db_table_name_processor(uchar *) override;
4083+
4084+
/**
4085+
Checks if the current object represents an asterisk select list item
4086+
4087+
@returns false if a regular column reference, true if an asterisk
4088+
select list item.
4089+
*/
4090+
virtual bool is_asterisk() const { return false; }
4091+
};
4092+
4093+
/**
4094+
Represents [schema.][table.]* in a select list
4095+
4096+
Item_asterisk is used to insert placeholder objects for the special
4097+
select list item * (asterisk) into AST.
4098+
Those placeholder objects are to be substituted later with e.g. a list of real
4099+
table columns by a resolver (@see setup_wild).
4100+
4101+
@todo The parent class Item_field is redundant. Refactor setup_wild() to
4102+
replace Item_field with a simpler one.
4103+
*/
4104+
class Item_asterisk : public Item_field {
4105+
typedef Item_field super;
4106+
4107+
public:
4108+
/**
4109+
Constructor
4110+
4111+
@param pos Location of the * (asterisk) lexeme.
4112+
@param opt_schema_name Schema name or nullptr.
4113+
@param opt_table_name Table name or nullptr.
4114+
*/
4115+
Item_asterisk(const POS &pos, const char *opt_schema_name,
4116+
const char *opt_table_name)
4117+
: super(pos, opt_schema_name, opt_table_name, "*") {}
4118+
4119+
bool itemize(Parse_context *pc, Item **res) override;
4120+
bool fix_fields(THD *, Item **) override {
4121+
DBUG_ASSERT(false); // should never happen: see setup_wild()
4122+
return true;
4123+
}
4124+
bool is_asterisk() const override { return true; }
40834125
};
40844126

40854127
// See if the provided item points to a reachable field (one that belongs to a

sql/parse_tree_items.cc

-12
Original file line numberDiff line numberDiff line change
@@ -162,18 +162,6 @@ static Item *handle_sql2003_note184_exception(Parse_context *pc, Item *left,
162162
return result;
163163
}
164164

165-
bool PTI_table_wild::itemize(Parse_context *pc, Item **item) {
166-
if (super::itemize(pc, item)) return true;
167-
168-
schema = pc->thd->get_protocol()->has_client_capability(CLIENT_NO_SCHEMA)
169-
? nullptr
170-
: schema;
171-
*item = new (pc->mem_root) Item_field(POS(), schema, table, "*");
172-
if (*item == nullptr || (*item)->itemize(pc, item)) return true;
173-
pc->select->with_wild++;
174-
return false;
175-
}
176-
177165
bool PTI_comp_op::itemize(Parse_context *pc, Item **res) {
178166
if (super::itemize(pc, res) || left->itemize(pc, &left) ||
179167
right->itemize(pc, &right))

sql/parse_tree_items.h

-14
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,6 @@ class PT_subquery;
4242
class PT_window;
4343
struct udf_func;
4444

45-
class PTI_table_wild : public Parse_tree_item {
46-
typedef Parse_tree_item super;
47-
48-
const char *schema;
49-
const char *table;
50-
51-
public:
52-
explicit PTI_table_wild(const POS &pos, const char *schema_arg,
53-
const char *table_arg)
54-
: super(pos), schema(schema_arg), table(table_arg) {}
55-
56-
bool itemize(Parse_context *pc, Item **item) override;
57-
};
58-
5945
class PTI_truth_transform : public Parse_tree_item {
6046
typedef Parse_tree_item super;
6147

sql/sql_resolver.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -1433,9 +1433,10 @@ bool SELECT_LEX::setup_wild(THD *thd) {
14331433

14341434
while (with_wild && (item = it++)) {
14351435
Item_field *item_field;
1436-
if (item->type() == Item::FIELD_ITEM && (item_field = (Item_field *)item) &&
1437-
item_field->field_name && item_field->field_name[0] == '*' &&
1438-
!item_field->field) {
1436+
if (item->type() == Item::FIELD_ITEM &&
1437+
(item_field = down_cast<Item_field *>(item)) &&
1438+
item_field->is_asterisk()) {
1439+
DBUG_ASSERT(item_field->field == nullptr);
14391440
const uint elem = fields_list.elements;
14401441
const bool any_privileges = item_field->any_privileges;
14411442
Item_subselect *subsel = master_unit()->item;

sql/sql_show_status.cc

+2-4
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ static SELECT_LEX *build_query(const POS &pos, THD *thd,
101101
static const LEX_CSTRING as_value = {STRING_WITH_LEN("Value")};
102102
static const LEX_CSTRING pfs = {STRING_WITH_LEN("performance_schema")};
103103

104-
static const LEX_CSTRING star = {STRING_WITH_LEN("*")};
105-
106104
static const Query_options options = {
107105
0 /* query_spec_options */
108106
};
@@ -198,8 +196,8 @@ static SELECT_LEX *build_query(const POS &pos, THD *thd,
198196
if (table_reference_list1.push_back(derived_table)) return nullptr;
199197

200198
/* SELECT * ... */
201-
PTI_simple_ident_ident *ident_star;
202-
ident_star = new (thd->mem_root) PTI_simple_ident_ident(pos, star);
199+
Item_asterisk *ident_star;
200+
ident_star = new (thd->mem_root) Item_asterisk(pos, nullptr, nullptr);
203201
if (ident_star == nullptr) return nullptr;
204202

205203
PT_select_item_list *item_list1;

sql/sql_yacc.yy

+16-19
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Note: YYTHD is passed as an argument to yyparse(), and subsequently to yylex().
3737
#define YYPS (& YYTHD->m_parser_state->m_yacc)
3838
#define YYCSCL (YYLIP->query_charset)
3939
#define YYMEM_ROOT (YYTHD->mem_root)
40+
#define YYCLIENT_NO_SCHEMA (YYTHD->get_protocol()->has_client_capability(CLIENT_NO_SCHEMA))
4041

4142
#define YYINITDEPTH 100
4243
#define YYMAXDEPTH 3200 /* Because of 64K stack */
@@ -9458,9 +9459,9 @@ query_primary:
94589459
| explicit_table
94599460
{
94609461
auto item_list= NEW_PTN PT_select_item_list;
9461-
if (item_list == nullptr ||
9462-
item_list->push_back(
9463-
NEW_PTN Item_field(@$, nullptr, nullptr, "*")))
9462+
auto asterisk= NEW_PTN Item_asterisk(@$, nullptr, nullptr);
9463+
if (item_list == nullptr || asterisk == nullptr ||
9464+
item_list->push_back(asterisk))
94649465
MYSQL_YYABORT;
94659466
$$= NEW_PTN PT_explicit_table({}, item_list, $1);
94669467
}
@@ -9653,9 +9654,9 @@ select_item_list:
96539654
}
96549655
| '*'
96559656
{
9656-
Item *item= NEW_PTN Item_field(@$, NULL, NULL, "*");
9657-
$$= NEW_PTN PT_select_item_list;
9658-
if ($$ == NULL || $$->push_back(item))
9657+
Item *item = NEW_PTN Item_asterisk(@$, nullptr, nullptr);
9658+
$$ = NEW_PTN PT_select_item_list;
9659+
if ($$ == nullptr || item == nullptr || $$->push_back(item))
96599660
MYSQL_YYABORT;
96609661
}
96619662
;
@@ -14206,13 +14207,14 @@ insert_ident:
1420614207
table_wild:
1420714208
ident '.' '*'
1420814209
{
14209-
$$= NEW_PTN PTI_table_wild(@$, NULL, $1.str);
14210+
$$ = NEW_PTN Item_asterisk(@$, nullptr, $1.str);
1421014211
}
1421114212
| ident '.' ident '.' '*'
1421214213
{
1421314214
if (check_and_convert_db_name(&$1, false) != Ident_name_check::OK)
1421414215
MYSQL_YYABORT;
14215-
$$= NEW_PTN PTI_table_wild(@$, $1.str, $3.str);
14216+
auto schema_name = YYCLIENT_NO_SCHEMA ? nullptr : $1.str;
14217+
$$ = NEW_PTN Item_asterisk(@$, schema_name, $3.str);
1421614218
}
1421714219
;
1421814220

@@ -14268,11 +14270,9 @@ table_ident:
1426814270
}
1426914271
| ident '.' ident
1427014272
{
14271-
if (YYTHD->get_protocol()->has_client_capability(CLIENT_NO_SCHEMA))
14272-
$$= NEW_PTN Table_ident(to_lex_cstring($3));
14273-
else {
14274-
$$= NEW_PTN Table_ident(to_lex_cstring($1), to_lex_cstring($3));
14275-
}
14273+
auto schema_name = YYCLIENT_NO_SCHEMA ? LEX_CSTRING{}
14274+
: to_lex_cstring($1.str);
14275+
$$= NEW_PTN Table_ident(schema_name, to_lex_cstring($3));
1427614276
if ($$ == NULL)
1427714277
MYSQL_YYABORT;
1427814278
}
@@ -15998,12 +15998,9 @@ grant_ident:
1599815998
}
1599915999
| schema '.' ident
1600016000
{
16001-
Table_ident *tmp;
16002-
if (YYTHD->get_protocol()->has_client_capability(CLIENT_NO_SCHEMA))
16003-
tmp = NEW_PTN Table_ident(to_lex_cstring($3));
16004-
else {
16005-
tmp = NEW_PTN Table_ident(to_lex_cstring($1), to_lex_cstring($3));
16006-
}
16001+
auto schema_name = YYCLIENT_NO_SCHEMA ? LEX_CSTRING{}
16002+
: to_lex_cstring($1.str);
16003+
auto tmp = NEW_PTN Table_ident(schema_name, to_lex_cstring($3));
1600716004
if (tmp == NULL)
1600816005
MYSQL_YYABORT;
1600916006
LEX *lex=Lex;

0 commit comments

Comments
 (0)