Commit graph

177153 commits

Author SHA1 Message Date
Monty
546e7aa96f MDEV-8203 Assert in Query_log_event::do_apply_event()
This happens because the master writes a table_map event to the binary log, but no row event.
The slave has a check that there should always be a row event if there was a table_map event, which
causes a crash.

Fixed by remembering in the cache what kind of events are logged
and ignore cached statements which is just a table map event.
2017-04-07 15:58:17 +04:00
Alexander Barkov
ed305c0fd5 MDEV-12461 TYPE OF and ROW TYPE OF anchored data types 2017-04-07 13:40:27 +04:00
Alexander Barkov
113a980ff1 MDEV-12457 Cursors with parameters 2017-04-07 06:30:16 +04:00
Alexander Barkov
75d1962a24 Using the -t command line to bison instead of %name-prefix
Needed to compile on machines with older bison versions.
Adding a new parameter "name_prefix" to RUN_BISON() cmake macro.
2017-04-07 06:30:05 +04:00
Alexander Barkov
191f262600 Fixing that "mtr --ps compat/oracle.sp-row" failed due to a wrong position of the DELIMITER command 2017-04-07 06:29:16 +04:00
Alexander Barkov
e1cff0ac5d MDEV-12441 Variables declared after cursors with parameters lose values
Parse context frames (sp_pcontext) can have holes in variable run-time offsets,
the missing offsets reside on the children contexts in such cases.

Example:

  CREATE PROCEDURE p1() AS
    x0 INT:=100;        -- context 0, position 0, run-time 0
    CURSOR cur(
      p0 INT,           -- context 1, position 0, run-time 1
      p1 INT            -- context 1, position 1, run-time 2
    ) IS SELECT p0, p1;
    x1 INT:=101;        -- context 0, position 1, run-time 3
  BEGIN
    ...
  END;

Fixing a few methods to take this into account:
- sp_pcontext::find_variable()
- sp_pcontext::retrieve_field_definitions()
- LEX::sp_variable_declarations_init()
- LEX::sp_variable_declarations_finalize()
- LEX::sp_variable_declarations_rowtype_finalize()
- LEX::sp_variable_declarations_with_ref_finalize()

Adding a convenience method:

  sp_pcontext::get_last_context_variable(uint offset_from_the_end);

to access variables from the end, rather than from the beginning.
This helps to loop through the context variable array (m_vars)
on the fragment that does not have any holes.

Additionally, renaming sp_pcontext::find_context_variable() to
sp_pcontext::get_context_variable(). This method simply returns
the variable by its index. So let's rename to avoid assumptions
that some heavy lookup is going on inside.
2017-04-05 15:03:02 +04:00
Alexander Barkov
d433277f53 A cleanup for MDEV-10914 ROW data type for stored routine variables
Addressing Monty's review suggestions
2017-04-05 15:03:02 +04:00
Alexander Barkov
cae6bf2b9c Cleanup for MDEV-10581 sql_mode=ORACLE: Explicit cursor FOR LOOP
Addressing Monty's review suggestions.
2017-04-05 15:03:02 +04:00
Alexander Barkov
ce4b291b51 A cleanup patch for MDEV-12011 sql_mode=ORACLE: cursor%ROWTYPE in variable declarations
Addressing Monty's review suggestions
2017-04-05 15:03:02 +04:00
Alexander Barkov
48a7ea6da3 Uninitialized Column_definition::pack_flag for ROW-type SP variables and their fields
Fixed that the Column_definition::pack_flag member corresponding to
ROW-type SP variables and their fields was not properly initialized.
This lead to sporadic test failures. Valgrind complained about jumps
depending on uninitialized value in VALGRIND builds.

This patch makes sure that sp_head::fill_spvar_definition() is always
called for ROW variables and their fields.

Additionally, fixed that a function with a scalar parameter
erroneously acceptes ROWs with one fields. Now an error is returned.
2017-04-05 15:03:01 +04:00
Alexander Barkov
281f8a42ee MDEV-12089 sql_mode=ORACLE: Understand optional routine name after the END keyword 2017-04-05 15:03:01 +04:00
Alexander Barkov
891c1e2dd0 An additional test for MDEV-12347 Valgrind reports invalid read errors in Item_field_row::element_index_by_name 2017-04-05 15:03:01 +04:00
Alexander Barkov
01457ec280 MDEV-12347 Valgrind reports invalid read errors in Item_field_row::element_index_by_name 2017-04-05 15:03:01 +04:00
Alexander Barkov
ec19e48021 MDEV-12314 Implicit cursor FOR LOOP for cursors with parameters 2017-04-05 15:03:00 +04:00
Alexander Barkov
e0451941cc MDEV-12291 Allow ROW variables as SELECT INTO targets 2017-04-05 15:03:00 +04:00
Alexander Barkov
9dfe7bf86d MDEV-10598 Variable declarations can go after cursor declarations
Based on a contributed patch from Jerome Brauge.
2017-04-05 15:03:00 +04:00
Alexander Barkov
84c55a5668 MDEV-10581 sql_mode=ORACLE: Explicit cursor FOR LOOP
MDEV-12098 sql_mode=ORACLE: Implicit cursor FOR loop
2017-04-05 15:02:59 +04:00
Alexander Barkov
f429b5a834 MDEV-12011 sql_mode=ORACLE: cursor%ROWTYPE in variable declarations
Implementing cursor%ROWTYPE variables, according to the task description.

This patch includes a refactoring in how sp_instr_cpush and sp_instr_copen
work. This is needed to implement MDEV-10598 later easier, to allow variable
declarations go after cursor declarations (which is currently not allowed).

Before this patch, sp_instr_cpush worked as a Query_arena associated with
the cursor. sp_instr_copen::execute() switched to the sp_instr_cpush's
Query_arena when executing the cursor SELECT statement.

Now the Query_arena associated with the cursor is stored inside an instance
of a new class sp_lex_cursor (a LEX descendand) that contains the cursor SELECT
statement.

This simplifies the implementation, because:
- It's easier to follow the code when everything related to execution
  of the cursor SELECT statement is stored inside the same sp_lex_cursor
  object (rather than distributed between LEX and sp_instr_cpush).
- It's easier to link an sp_instr_cursor_copy_struct to
  sp_lex_cursor rather than to sp_instr_cpush.
- Also, it allows to perform sp_instr_cursor_copy_struct::exec_core()
  without having a pointer to sp_instr_cpush, using a pointer to sp_lex_cursor
  instead. This will be important for MDEV-10598, because sp_instr_cpush will
  happen *after* sp_instr_cursor_copy_struct.

After MDEV-10598 is done, this declaration:

DECLARE
  CURSOR cur IS SELECT * FROM t1;
  rec cur%ROWTYPE;
BEGIN
  OPEN cur;
  FETCH cur INTO rec;
  CLOSE cur;
END;

will generate about this code:

+-----+--------------------------+
| Pos | Instruction              |
+-----+--------------------------+
|   0 | cursor_copy_struct rec@0 | Points to sp_cursor_lex through m_lex_keeper
|   1 | set rec@0 NULL           |
|   2 | cpush cur@0              | Points to sp_cursor_lex through m_lex_keeper
|   3 | copen cur@0              | Points to sp_cursor_lex through m_cursor
|   4 | cfetch cur@0 rec@0       |
|   5 | cclose cur@0             |
|   6 | cpop 1                   |
+-----+--------------------------+

Notice, "cursor_copy_struct" and "set" will go before "cpush".
Instructions at positions 0, 2, 3 point to the same sp_cursor_lex instance.
2017-04-05 15:02:59 +04:00
Alexander Barkov
1b8a0c879d MDEV-12133 sql_mode=ORACLE: table%ROWTYPE in variable declarations 2017-04-05 15:02:59 +04:00
Alexander Barkov
400de20279 MDEV-12209 sql_mode=ORACLE: Syntax error in a OPEN cursor with parameters makes the server crash
The bug was introduced in the patch for "MDEV-10597 Cursors with parameters".
The LEX created in assignment_source_expr was not put into
thd->lex->sphead->m_lex (the stack of LEX'es), so syntax error in "expr"
caused a wrong memory cleanup in sp_head::~sp_head().

The fix changes the code to use sp_head::push_lex() followed by
sp_head::restore_lex(), like it happens in all other similar cases.
2017-04-05 15:02:58 +04:00
Alexander Barkov
7ca2f816a8 Part#2 for MDEV-12107 sql_mode=ORACLE: Inside routines the CALL keywoard is optional
Allowing qualified procedure names to be used without the CALL keyword:

BEGIN
  test.p1(10);
  test.p2;
END;

Note:
- COMMIT and ROLLBACK cannot be used in a direct assignment anymore:
    COMMIT:= 10;
    ROLLBACK:= 10;
  But as they are reserved keywords in Oracle anyway, this is not a problem.
- SHUTDOWN now also cannot be used in direct a direct assignment:
    SHUTDOWN:=10;
  If this causes migration problems in the future, the grammar should
  be modified.

Note:
  Variables with names COMMIT, ROLLBACK and SHUTDOWN can still be assigned
  with the SET statement, e.g. SET COMMIT=10;
2017-04-05 15:02:58 +04:00
Alexander Barkov
29e7cf01c3 MDEV-12107 sql_mode=ORACLE: Inside routines the CALL keywoard is optional 2017-04-05 15:02:58 +04:00
Alexander Barkov
839e0947ee MDEV-12143 sql_mode=ORACLE: make the CONCAT function ignore NULL arguments 2017-04-05 15:02:57 +04:00
Alexander Barkov
915c5df865 MDEV-12088 sql_mode=ORACLE: Do not require BEGIN..END in multi-statement exception handlers in THEN clause 2017-04-05 15:02:57 +04:00
Alexander Barkov
99df09ecab MDEV-12086 sql_mode=ORACLE: allow SELECT UNIQUE as a synonym for SELECT DISTINCT 2017-04-05 15:02:57 +04:00
halfspawn
af7f287b3b MDEV-10697 GOTO statement 2017-04-05 15:02:57 +04:00
Alexander Barkov
d836f52be5 MDEV-12007 Allow ROW variables as a cursor FETCH target 2017-04-05 15:02:56 +04:00
Alexander Barkov
72f43df623 MDEV-10914 ROW data type for stored routine variables 2017-04-05 15:02:56 +04:00
Alexander Barkov
ffbb2bbc09 Removing redundant tests for "SET (global|local|session).varname"
This is covered in mysql-test/t/variables.test. There is no sense
to test this for every individual variables.

This is to reduce the coming soon patch for ROW-type routine variables,
which will change the error from ER_PARSE_ERROR to a new error
"unknown structured variable".
2017-04-05 15:02:56 +04:00
Alexander Barkov
81f32145fa MDEV-10655 Anonymous blocks 2017-04-05 15:02:55 +04:00
Alexander Barkov
08799831cc MDEV-11880 sql_mode=ORACLE: Make the concatenation operator ignore NULL arguments
Now when sql_mode=ORACLE, the concatenation operator || treats
NULLs as empty strings.

Based on the contributed patch from Jérôme Brauge.
2017-04-05 15:02:55 +04:00
Alexander Barkov
46255b0c0d Fixing that LEX::sp_add_for_loop_variable() did not initialize pack_flag
This fixes compat/oracle.sp test failure in release builds.
2017-04-05 15:02:55 +04:00
Alexander Barkov
46d076d67a MDEV-10577 sql_mode=ORACLE: %TYPE in variable declarations 2017-04-05 15:02:54 +04:00
Alexander Barkov
cd1afe0aac MDEV-10588 sql_mode=ORACLE: TRUNCATE TABLE t1 [ {DROP|REUSE} STORAGE ] 2017-04-05 15:02:54 +04:00
Alexander Barkov
c0576ba5ec MDEV-11275 sql_mode=ORACLE: CAST(..AS VARCHAR(N)) 2017-04-05 15:02:54 +04:00
Alexander Barkov
f8a714c848 MDEV-10597 Cursors with parameters 2017-04-05 15:02:53 +04:00
Alexander Barkov
4ed804aa4d MDEV-10587 sql_mode=ORACLE: User defined exceptions 2017-04-05 15:02:53 +04:00
Alexander Barkov
4d3818d30d MDEV-11037 Diagnostics_area refactoring for user defined exceptions
Part 2:

Moving the part of Sql_condition that contain condition items
(such as m_class_origin, m_cursor_name, etc) into a separate
class Sql_condition_items. This allows to remove duplicate code in
different Sql_condition constructors.

Also, introducing new Sql_condition constructors and removing the method
Sql_condition::set(). All code sequences that called an Sql_condition
constructor followed by Sql_condition::set() are now replaced to
the new constructor calls. This gives light performance improvement,
as the relevant members are now initialized only one time.
2017-04-05 15:02:53 +04:00
Alexander Barkov
6010662cb3 MDEV-11037 Diagnostics_area refactoring for user defined exceptions 2017-04-05 15:02:53 +04:00
Alexander Barkov
ffca1e4830 MDEV-10578 sql_mode=ORACLE: SP control functions SQLCODE, SQLERRM 2017-04-05 15:02:52 +04:00
Alexander Barkov
de6d40592c MDEV-10411 Providing compatibility for basic PL/SQL constructs
An additional change for "Part 9: EXCEPTION handlers"

This construct:
  EXCEPTION WHEN OTHERS THEN ...;
now catches warning-alike conditions, e.g. NO_DATA_FOUND.
2017-04-05 15:02:52 +04:00
Alexander Barkov
f7043858ba MDEV-10866 Extend PREPARE and EXECUTE IMMEDIATE to understand expressions
MDEV-10867 PREPARE..EXECUTE is not consistent about non-ASCII characters

Adding Oracle specific tests
2017-04-05 15:02:52 +04:00
Alexander Barkov
054d00a9a3 A fix for MDEV-10411 Providing compatibility for basic PL/SQL constructs (Part 6: Assignment operator)
Fixed that a crash in this script:

SET sql_mode=ORACLE;
max_sort_length:= 1024;
2017-04-05 15:02:52 +04:00
Alexander Barkov
7fa1ad14dc MDEV-10840 sql_mode=ORACLE: RAISE statement for predefined exceptions 2017-04-05 15:02:51 +04:00
Alexander Barkov
76714a5c9a MDEV-10582 sql_mode=ORACLE: explicit cursor attributes %ISOPEN, %ROWCOUNT, %FOUND, %NOTFOUND 2017-04-05 15:02:51 +04:00
Alexander Barkov
4bb87996b9 DEV-10583 sql_mode=ORACLE: SQL%ROWCOUNT
Fixed that EXPLAIN EXTENDED erroneously returned
"SQL%%ROWCOUNT" instead of "SQL%ROWCOUNT"
2017-04-05 15:02:51 +04:00
Alexander Barkov
a2a196c04c MDEV-10709 Expressions as parameters to Dynamic SQL
Adding Oracle-specific tests for stored functions as EXECUTE..USING parameters.
2017-04-05 15:02:50 +04:00
Alexander Barkov
417c8c9daf MDEV-10585 EXECUTE IMMEDIATE statement
Adding Oracle specific tests
2017-04-05 15:02:50 +04:00
Alexander Barkov
a699a5f967 MDEV-10583 sql_mode=ORACLE: SQL%ROWCOUNT 2017-04-05 15:02:50 +04:00
Alexander Barkov
ccb91eb3ce MDEV-10839 sql_mode=ORACLE: Predefined exceptions: TOO_MANY_ROWS, NO_DATA_FOUND, DUP_VAL_ON_INDEX 2017-04-05 15:02:50 +04:00