Skip to content

Commit 9f5adf0

Browse files
iqbal-hasprimeabarkov
authored andcommitted
MDEV-34317: Implement RECORD type
Implement `DECLARE TYPE type_name IS RECORD (..)` with scalar members in stored routines and anonymous blocks
1 parent 4c956fa commit 9f5adf0

File tree

15 files changed

+1964
-11
lines changed

15 files changed

+1964
-11
lines changed

mysql-test/suite/compat/oracle/r/sp-record.result

Lines changed: 775 additions & 0 deletions
Large diffs are not rendered by default.

mysql-test/suite/compat/oracle/t/sp-record.test

Lines changed: 840 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Start of 11.8 tests
2+
#
3+
# MDEV-34317 DECLARE TYPE type_name IS RECORD (..) with scalar members in stored routines
4+
#
5+
#
6+
# Demonstrate UDT field type with RECORD
7+
#
8+
SET sql_mode=ORACLE;
9+
DECLARE
10+
TYPE rec_t IS RECORD (
11+
a INT,
12+
b UUID
13+
);
14+
rec rec_t:= rec_t(1,'6021cf0b-94f8-11ef-b80e-e454e874f5e5');
15+
BEGIN
16+
CREATE TABLE t1 AS SELECT rec.a, rec.b;
17+
SHOW CREATE TABLE t1;
18+
SELECT * FROM t1;
19+
DROP TABLE t1;
20+
END;
21+
$$
22+
Table Create Table
23+
t1 CREATE TABLE "t1" (
24+
"rec.a" int(11) DEFAULT NULL,
25+
"rec.b" uuid DEFAULT NULL
26+
)
27+
rec.a rec.b
28+
1 6021cf0b-94f8-11ef-b80e-e454e874f5e5
29+
# End of 11.8 tests
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--echo # Start of 11.8 tests
2+
3+
--echo #
4+
--echo # MDEV-34317 DECLARE TYPE type_name IS RECORD (..) with scalar members in stored routines
5+
--echo #
6+
7+
8+
--echo #
9+
--echo # Demonstrate UDT field type with RECORD
10+
--echo #
11+
SET sql_mode=ORACLE;
12+
DELIMITER $$;
13+
DECLARE
14+
TYPE rec_t IS RECORD (
15+
a INT,
16+
b UUID
17+
);
18+
rec rec_t:= rec_t(1,'6021cf0b-94f8-11ef-b80e-e454e874f5e5');
19+
BEGIN
20+
CREATE TABLE t1 AS SELECT rec.a, rec.b;
21+
SHOW CREATE TABLE t1;
22+
SELECT * FROM t1;
23+
DROP TABLE t1;
24+
END;
25+
$$
26+
DELIMITER ;$$
27+
28+
--echo # End of 11.8 tests

sql/item.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,6 +1939,13 @@ bool Item_splocal_row_field::fix_fields(THD *thd, Item **ref)
19391939
{
19401940
DBUG_ASSERT(fixed() == 0);
19411941
Item *item= get_variable(thd->spcont)->element_index(m_field_idx);
1942+
/*
1943+
If a row field was declared using an anchored data type,
1944+
then its creation time type handler was type_handler_null.
1945+
Let's now copy the real type handler from the item, which
1946+
now contains the resolved data type.
1947+
*/
1948+
set_handler(item->type_handler());
19421949
return fix_fields_from_item(thd, ref, item);
19431950
}
19441951

sql/lex.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ SYMBOL symbols[] = {
515515
{ "READS", SYM(READS_SYM)},
516516
{ "REAL", SYM(REAL)},
517517
{ "REBUILD", SYM(REBUILD_SYM)},
518+
{ "RECORD", SYM(RECORD_SYM)},
518519
{ "RECOVER", SYM(RECOVER_SYM)},
519520
{ "RECURSIVE", SYM(RECURSIVE_SYM)},
520521
{ "REDO_BUFFER_SIZE", SYM(REDO_BUFFER_SIZE_SYM)},

sql/share/errmsg-utf8.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12145,9 +12145,8 @@ ER_UNKNOWN_OPERATOR
1214512145
eng "Operator does not exist: '%-.128s'"
1214612146
spa "El operador no existe: '%-.128s'"
1214712147
sw "Opereta haipo: '% -.128s'"
12148-
ER_UNUSED_29
12149-
eng "You should never see it"
12150-
sw "Hupaswi kuiona kamwe"
12148+
ER_SP_DUP_DECL
12149+
eng "Duplicate declaration: '%-.64s'"
1215112150
ER_PART_STARTS_BEYOND_INTERVAL
1215212151
eng "%`s: STARTS is later than query time, first history partition may exceed INTERVAL value"
1215312152
spa "%`s: STARTS es posterior al momento de consulta (query), la primera partición de historia puede exceder el valor INTERVAL"

sql/sp_head.cc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3933,6 +3933,38 @@ bool sp_head::spvar_fill_type_reference(THD *thd,
39333933
}
39343934

39353935

3936+
bool sp_head::spvar_def_fill_type_reference(THD *thd, Spvar_definition *def,
3937+
const LEX_CSTRING &table,
3938+
const LEX_CSTRING &column)
3939+
{
3940+
Qualified_column_ident *ref;
3941+
if (!(ref= new (thd->mem_root) Qualified_column_ident(&table, &column)))
3942+
return true;
3943+
3944+
def->set_column_type_ref(ref);
3945+
m_flags|= sp_head::HAS_COLUMN_TYPE_REFS;
3946+
3947+
return false;
3948+
}
3949+
3950+
3951+
bool sp_head::spvar_def_fill_type_reference(THD *thd, Spvar_definition *def,
3952+
const LEX_CSTRING &db,
3953+
const LEX_CSTRING &table,
3954+
const LEX_CSTRING &column)
3955+
{
3956+
Qualified_column_ident *ref;
3957+
if (!(ref= new (thd->mem_root) Qualified_column_ident(thd, &db, &table,
3958+
&column)))
3959+
return true;
3960+
3961+
def->set_column_type_ref(ref);
3962+
m_flags|= sp_head::HAS_COLUMN_TYPE_REFS;
3963+
3964+
return false;
3965+
}
3966+
3967+
39363968
bool sp_head::spvar_fill_table_rowtype_reference(THD *thd,
39373969
sp_variable *spvar,
39383970
const LEX_CSTRING &table)

sql/sp_head.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,14 @@ class sp_head :private Query_arena,
815815
const LEX_CSTRING &db,
816816
const LEX_CSTRING &table);
817817

818+
bool spvar_def_fill_type_reference(THD *thd, Spvar_definition *def,
819+
const LEX_CSTRING &table,
820+
const LEX_CSTRING &column);
821+
bool spvar_def_fill_type_reference(THD *thd, Spvar_definition *def,
822+
const LEX_CSTRING &db,
823+
const LEX_CSTRING &table,
824+
const LEX_CSTRING &column);
825+
818826
void set_c_chistics(const st_sp_chistics &chistics);
819827
void set_info(longlong created, longlong modified,
820828
const st_sp_chistics &chistics, sql_mode_t sql_mode);

sql/sp_pcontext.cc

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ sp_pcontext::sp_pcontext()
9494
m_parent(NULL), m_pboundary(0),
9595
m_vars(PSI_INSTRUMENT_MEM), m_case_expr_ids(PSI_INSTRUMENT_MEM),
9696
m_conditions(PSI_INSTRUMENT_MEM), m_cursors(PSI_INSTRUMENT_MEM),
97-
m_handlers(PSI_INSTRUMENT_MEM), m_children(PSI_INSTRUMENT_MEM),
98-
m_scope(REGULAR_SCOPE)
97+
m_handlers(PSI_INSTRUMENT_MEM), m_records(PSI_INSTRUMENT_MEM),
98+
m_children(PSI_INSTRUMENT_MEM), m_scope(REGULAR_SCOPE)
9999
{
100100
init(0, 0, 0);
101101
}
@@ -107,8 +107,8 @@ sp_pcontext::sp_pcontext(sp_pcontext *prev, sp_pcontext::enum_scope scope)
107107
m_parent(prev), m_pboundary(0),
108108
m_vars(PSI_INSTRUMENT_MEM), m_case_expr_ids(PSI_INSTRUMENT_MEM),
109109
m_conditions(PSI_INSTRUMENT_MEM), m_cursors(PSI_INSTRUMENT_MEM),
110-
m_handlers(PSI_INSTRUMENT_MEM), m_children(PSI_INSTRUMENT_MEM),
111-
m_scope(scope)
110+
m_handlers(PSI_INSTRUMENT_MEM), m_records(PSI_INSTRUMENT_MEM),
111+
m_children(PSI_INSTRUMENT_MEM), m_scope(scope)
112112
{
113113
init(prev->m_var_offset + prev->m_max_var_index,
114114
prev->current_cursor_count(),
@@ -409,6 +409,40 @@ sp_condition_value *sp_pcontext::find_condition(const LEX_CSTRING *name,
409409
NULL;
410410
}
411411

412+
413+
bool sp_pcontext::add_record(THD *thd, const Lex_ident_column &name,
414+
Row_definition_list *field)
415+
{
416+
sp_record *p= new (thd->mem_root) sp_record(name, field);
417+
418+
if (p == NULL)
419+
return true;
420+
421+
return m_records.append(p);
422+
}
423+
424+
425+
sp_record *sp_pcontext::find_record(const LEX_CSTRING *name,
426+
bool current_scope_only) const
427+
{
428+
size_t i= m_records.elements();
429+
430+
while (i--)
431+
{
432+
sp_record *p= m_records.at(i);
433+
434+
if (p->eq_name(name))
435+
{
436+
return p;
437+
}
438+
}
439+
440+
return (!current_scope_only && m_parent) ?
441+
m_parent->find_record(name, false) :
442+
NULL;
443+
}
444+
445+
412446
sp_condition_value *
413447
sp_pcontext::find_declared_or_predefined_condition(THD *thd,
414448
const LEX_CSTRING *name)

0 commit comments

Comments
 (0)