summaryrefslogtreecommitdiff
path: root/sql/sql_yacc.yy
Commit message (Collapse)AuthorAgeFilesLines
* Merge branch '10.2' into 10.3st-10.3-wladVladislav Vaintroub2021-10-031-1/+2
|\
| * Fix MSVC warning with bison 3.8.2Vladislav Vaintroub2021-10-031-1/+2
| |
* | Merge 10.2 into 10.3Marko Mäkelä2021-09-221-0/+3
|\ \ | |/
| * Silence a warning about unused Bison labelMarko Mäkelä2021-09-221-0/+3
| |
* | Merge branch '10.2' into 10.3Vladislav Vaintroub2021-09-111-1/+1
|\ \ | |/ | | | | | | | | # Conflicts: # cmake/os/Windows.cmake # sql/sql_yacc.yy
| * Bison 3.7 - fix "conversion from 'ptrdiff_t' to 'ulong', possible loss of data"Vladislav Vaintroub2021-09-111-2/+2
| |
* | MDEV-25484 Crash when parsing query using derived table containing TVCIgor Babaev2021-07-231-4/+8
| | | | | | | | | | | | | | | | | | | | | | This patch fixes parsing problems concerning derived tables that use table value constructors (TVC) with LIMIT and ORDER BY clauses of the form ((VALUES ... LIMIT ...) ORDER BY ...) as dt The fix has to be applied only to 10.3 as 10.4 that employs a different grammar rules has no such problems. The test cases should be merged upstream. Approved by Oleksandr Byelkin <sanja@mariadb.com>
* | Merge branch '10.2' into 10.3Sergei Golubchik2021-07-211-18/+28
|\ \ | |/
| * MDEV-23597 Assertion `marked_for_read()' failed while evaluating DEFAULTNikita Malyavin2021-07-161-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The columns that are part of DEFAULT expression were not read-marked in statements like UPDATE...SET b=DEFAULT. The problem is `F(DEFAULT)` expression depends of the left-hand side of an assignment. However, setup_fields accepts only right-hand side value. Neither Item::fix_fields does. Suchwise, b=DEFAULT(b) works fine, because Item_default_field has information on what field it is default of: if (thd->mark_used_columns != MARK_COLUMNS_NONE) def_field->default_value->expr->update_used_tables(); in Item_default_value::fix_fields(). It is not reasonable to pass a left-hand side to Item:fix_fields, because the case is rare, so the rewrite b= F(DEFAULT) -> b= F(DEFAULT(b)) is made instead. Both UPDATE and multi-UPDATE are affected, however any form of INSERT is not: it marks all the fields in DEFAULT expressions for read in TABLE::mark_default_fields_for_write().
* | Merge 10.2 into 10.3Marko Mäkelä2021-05-241-8/+53
|\ \ | |/
| * MDEV-23886 Reusing CTE inside a function fails with table doesn't existIgor Babaev2021-05-211-11/+55
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In the code existed just before this patch binding of a table reference to the specification of the corresponding CTE happens in the function open_and_process_table(). If the table reference is not the first in the query the specification is cloned in the same way as the specification of a view is cloned for any reference of the view. This works fine for standalone queries, but does not work for stored procedures / functions for the following reason. When the first call of a stored procedure/ function SP is processed the body of SP is parsed. When a query of SP is parsed the info on each encountered table reference is put into a TABLE_LIST object linked into a global chain associated with the query. When parsing of the query is finished the basic info on the table references from this chain except table references to derived tables and information schema tables is put in one hash table associated with SP. When parsing of the body of SP is finished this hash table is used to construct TABLE_LIST objects for all table references mentioned in SP and link them into the list of such objects passed to a pre-locking process that calls open_and_process_table() for each table from the list. When a TABLE_LIST for a view is encountered the view is opened and its specification is parsed. For any table reference occurred in the specification a new TABLE_LIST object is created to be included into the list for pre-locking. After all objects in the pre-locking have been looked through the tables mentioned in the list are locked. Note that the objects referenced CTEs are just skipped here as it is impossible to resolve these references without any info on the context where they occur. Now the statements from the body of SP are executed one by one that. At the very beginning of the execution of a query the tables used in the query are opened and open_and_process_table() now is called for each table reference mentioned in the list of TABLE_LIST objects associated with the query that was built when the query was parsed. For each table reference first the reference is checked against CTEs definitions in whose scope it occurred. If such definition is found the reference is considered resolved and if this is not the first reference to the found CTE the the specification of the CTE is re-parsed and the result of the parsing is added to the parsing tree of the query as a sub-tree. If this sub-tree contains table references to other tables they are added to the list of TABLE_LIST objects associated with the query in order the referenced tables to be opened. When the procedure that opens the tables comes to the TABLE_LIST object created for a non-first reference to a CTE it discovers that the referenced table instance is not locked and reports an error. Thus processing non-first table references to a CTE similar to how references to view are processed does not work for queries used in stored procedures / functions. And the main problem is that the current pre-locking mechanism employed for stored procedures / functions does not allow to save the context in which a CTE reference occur. It's not trivial to save the info about the context where a CTE reference occurs while the resolution of the table reference cannot be done without this context and consequentially the specification for the table reference cannot be determined. This patch solves the above problem by moving resolution of all CTE references at the parsing stage. More exactly references to CTEs occurred in a query are resolved right after parsing of the query has finished. After resolution any CTE reference it is marked as a reference to to derived table. So it is excluded from the hash table created for pre-locking used base tables and view when the first call of a stored procedure / function is processed. This solution required recursive calls of the parser. The function THD::sql_parser() has been added specifically for recursive invocations of the parser.
| * Bug#29363867: LOST CONNECTION TO MYSQL SERVER DURING QUERYbb-10.2-BUG29363867Oleksandr Byelkin2021-04-281-4/+24
| | | | | | | | | | | | | | | | | | | | | | | | The problem is that sharing default expression among set instruction leads to attempt access result field of function created in other instruction runtime MEM_ROOT and already freed (a bit different then MySQL problem). Fix is the same as in MySQL (but no optimisation for constant), turn DECLARE a, b, c type DEFAULT expr; to DECLARE a type DEFAULT expr, b type DEFAULT a, c type DEFAULT a;
* | MDEV-22786 Crashes with nested table value constructorsIgor Babaev2021-03-031-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The bug caused crashes of the server when processing queries with nested table value constructors (TVC) . It happened because the grammar rules to parse TVC used the same global lists for both nested TVC and nesting TVC. As a result invalid select trees were constructed for queries with nested TVC and this led to crashes at the prepare stage. This patch provides its own lists structures for each TVC nest level. Besides the patch fixes a bug in the function wrap_tvc() that missed inheritance of the SELECT_LEX::exclude_from_table_unique_test for selects that wrapped TVCs. This inheritance is critical for specifications of derived tables that employ nested TVCs. Approved by dmitry.shulga@mariadb.com
* | Merge branch '10.2' into 10.3Sergei Golubchik2021-02-011-29/+39
|\ \ | |/
| * don't allow `KILL QUERY ID USER xxx`Sergei Golubchik2021-01-241-7/+11
| |
| * MDEV-12161 Can't specify collation for virtual columnsSergei Golubchik2021-01-111-20/+22
| | | | | | | | | | | | | | | | | | | | | | sql standard (2016) allows <collate clause> in two places in the <column definition> - as a part of the <data type> or at the very end. Let's do that too. Side effect: in column/SP declaration `COLLATE cs_coll` automatically implies `CHARACTER SET cs` (unless charset was specified explicitly). See changes in sp-ucs2.result
* | Merge branch '10.2' into 10.3Oleksandr Byelkin2020-12-231-9/+5
|\ \ | |/
| * MDEV-24194 View definition corruptionSergei Golubchik2020-12-101-10/+6
| | | | | | | | fix parsing of "1 IS NULL = 2"
* | Merge 10.2 into 10.3Marko Mäkelä2020-10-281-69/+63
|\ \ | |/
| * precedence bugfixingSergei Golubchik2020-10-231-55/+60
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | fix printing precedence for BETWEEN, LIKE/ESCAPE, REGEXP, IN don't use precedence for printing CASE/WHEN/THEN/ELSE/END fix parsing precedence of BETWEEN, LIKE/ESCAPE, REGEXP, IN support predicate arguments for IN, BETWEEN, SOUNDS LIKE, LIKE/ESCAPE, REGEXP use %nonassoc for unary operators fix parsing of IS TRUE/FALSE/UNKNOWN/NULL remove parser_precedence test as superseded by the precedence test
* | Merge 10.2 into 10.3Marko Mäkelä2020-10-221-1/+3
|\ \ | |/
| * MDEV-18163 Assertion `table_share->tmp_table != NO_TMP_TABLE || m_lock_type ↵Oleksandr Byelkin2020-10-061-0/+2
| | | | | | | | | | | | != 2' failed in handler::ha_rnd_next(); / Assertion `table_list->table' failed in find_field_in_table_ref / ERROR 1901 (on optimized builds) Add the same check for altering DEFAULT used as for CREATE TABLE.
* | Fix GCC 10.2.0 -Og -Wmaybe-uninitializedMarko Mäkelä2020-08-131-4/+8
| | | | | | | | | | | | Fix some more cases after merging commit 31aef3ae99dff6b7154cf288b3dc508d367f19f8. Some warnings look possibly genuine, others are clearly bogus.
* | MDEV-19632 Replication aborts with ER_SLAVE_CONVERSION_FAILED upon CREATE ↵Alexander Barkov2020-08-011-26/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ... SELECT in ORACLE mode - Adding optional qualifiers to data types: CREATE TABLE t1 (a schema.DATE); Qualifiers now work only for three pre-defined schemas: mariadb_schema oracle_schema maxdb_schema These schemas are virtual (hard-coded) for now, but may turn into real databases on disk in the future. - mariadb_schema.TYPE now always resolves to a true MariaDB data type TYPE without sql_mode specific translations. - oracle_schema.DATE translates to MariaDB DATETIME. - maxdb_schema.TIMESTAMP translates to MariaDB DATETIME. - Fixing SHOW CREATE TABLE to use a qualifier for a data type TYPE if the current sql_mode translates TYPE to something else. The above changes fix the reported problem, so this script: SET sql_mode=ORACLE; CREATE TABLE t2 AS SELECT mariadb_date_column FROM t1; is now replicated as: SET sql_mode=ORACLE; CREATE TABLE t2 (mariadb_date_column mariadb_schema.DATE); and the slave can unambiguously treat DATE as the true MariaDB DATE without ORACLE specific translation to DATETIME. Similar, SET sql_mode=MAXDB; CREATE TABLE t2 AS SELECT mariadb_timestamp_column FROM t1; is now replicated as: SET sql_mode=MAXDB; CREATE TABLE t2 (mariadb_timestamp_column mariadb_schema.TIMESTAMP); so the slave treats TIMESTAMP as the true MariaDB TIMESTAMP without MAXDB specific translation to DATETIME.
* | MDEV-21995 Server crashes in Item_field::real_type_handler with table value ↵Alexander Barkov2020-05-191-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | constructor 1. Code simplification: Item_default_value handled all these values: a. DEFAULT(field) b. DEFAULT c. IGNORE and had various conditions to distinguish (a) from (b) and from (c). Introducing a new abstract class Item_contextually_typed_value_specification, to handle (b) and (c), so the hierarchy now looks as follows: Item Item_result_field Item_ident Item_field Item_default_value - DEFAULT(field) Item_contextually_typed_value_specification Item_default_specification - DEFAULT Item_ignore_specification - IGNORE 2. Introducing a new virtual method is_evaluable_expression() to determine if an Item is: - a normal expression, so its val_xxx()/get_date() methods can be called - or a just an expression substitute, whose value methods cannot be called. 3. Disallowing Items that are not evalualble expressions in table value constructors.
* | MDEV-16288 ALTER TABLE…ALGORITHM=DEFAULT does not override alter_algorithmThirunarayanan Balathandayuthapani2020-05-041-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | - ALTER_ALGORITHM should be substituted when there is no mention of algorithm in alter statement. - Introduced algorithm(thd) in Alter_info. It returns the user requested algorithm. If user doesn't specify algorithm explicitly then it returns alter_algorithm variable. - changed algorithm() to get_algorithm(thd) to return algorithm name for displaying the error. - set_requested_algorithm(algo_value) to avoid direct assignment on requested_algorithm variable. - Avoid direct access of requested_algorithm to encapsulate requested_algorithm variable
* | Merge branch '10.2' into 10.3Oleksandr Byelkin2020-03-061-2/+2
|\ \ | |/
| * MDEV-17941 ALTER USER IF EXISTS does not work, although documentation says ↵Alexey Botchkov2020-02-111-2/+2
| | | | | | | | | | | | | | it should. Mistake in syntax definition fixed - should be ALTER USER IF EXISTS, not ALTER IF EXISTS USER.
| * Merge branch '10.1' into 10.2Sergei Petrunia2020-01-171-1/+1
| |\ | | | | | | | | | | | | | | | | | | # Conflicts: # sql/sp_head.cc # sql/sql_select.cc # sql/sql_trigger.cc
| | * MDEV-21341: Fix UBSAN failures: Issue SixSergei Petrunia2020-01-141-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (Variant #2 of the patch, which keeps the sp_head object inside the MEM_ROOT that sp_head object owns) (10.3 requires extra work due to sp_package, will commit a separate patch for it) sp_head::operator new() and operator delete() were dereferencing sp_head* pointers to memory that didn't hold a valid sp_head object (it was not created/already destroyed). This caused UBSan to crash when looking up type information. Fixed by providing static sp_head::create() and sp_head::destroy() methods.
* | | MDEV-18727 improve DML operation of System VersioningAleksey Midenkov2019-11-221-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | MDEV-18957 UPDATE with LIMIT clause is wrong for versioned partitioned tables UPDATE, DELETE: replace linear search of current/historical records with vers_setup_conds(). Additional DML cases in view.test
* | | MDEV-20074: Lost connection on update triggerOleksandr Byelkin2019-10-171-3/+10
| | | | | | | | | | | | | | | Instead of checking lex->sql_command which does not corect in case of triggers mark tables for insert.
* | | Merge 10.2 into 10.3Marko Mäkelä2019-09-231-2/+0
|\ \ \ | |/ /
| * | MDEV-19679 - CREATE SERVER needs tweaks for compatibility with CONNECT engineAnel Husakovic2019-09-201-1/+0
| | |
* | | Adding missing semicolons to sql_yacc.yy (10.3), indentation cleanups.Alexander Barkov2019-09-111-15/+18
| | |
* | | Merge remote-tracking branch 'origin/10.2' into 10.3Alexander Barkov2019-09-111-16/+37
|\ \ \ | |/ /
| * | Adding missing semicolons to sql_yacc.yy (10.2)Alexander Barkov2019-09-111-16/+38
| | |
* | | MDEV-18501 Partition pruning doesn't work for historical queries (cleanup)Aleksey Midenkov2019-09-011-4/+4
| | | | | | | | | | | | Cleanup removes useless allocation.
* | | MDEV-19127 Assertion `row_start_field' failed in vers_prepare_keys upon ↵Aleksey Midenkov2019-08-111-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | ALTER TABLE Prevent conflicting clauses at parser level. Clear HA_VERSIONED_TABLE flag for DROP SYSTEM VERSIONING (for the sake of strictness).
* | | MDEV-20263 sql_mode=ORACLE: BLOB(65535) should not translate to LONGBLOBAlexander Barkov2019-08-061-1/+6
| | |
* | | Merge branch '10.2' into 10.3Oleksandr Byelkin2019-07-261-18/+20
|\ \ \ | |/ /
| * | Merge branch '10.1' into 10.2Oleksandr Byelkin2019-07-261-16/+19
| |\ \ | | |/
| | * Merge branch '5.5' into 10.1Oleksandr Byelkin2019-07-251-16/+19
| | |\
| | | * MDEV-19421 Basic 3-way join queries are not parsed.Igor Babaev2019-07-111-24/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The parser returned a syntax error message for the queries with join expressions like this t1 JOIN t2 [LEFT | RIGHT] JOIN t3 ON ... ON ... when the second operand of the outer JOIN operation with ON clause was another join expression with ON clause. In this expression the JOIN operator is right-associative, i.e. expression has to be parsed as the expression t1 JOIN (t2 [LEFT | RIGHT] JOIN t3 ON ... ) ON ... Such join expressions are hard to parse because the outer JOIN is left-associative if there is no ON clause for the first outer JOIN operator. The patch implements the solution when the JOIN operator is always parsed as right-associative and builds first the right-associative tree. If it happens that there is no corresponding ON clause for this operator the tree is converted to left-associative. The idea of the solution was taken from the patch by Martin Hansson "WL#8083: Fixed the join_table rule" from MySQL-8.0 code line. As the grammar rules related to join expressions in MySQL-8.0 and MariaDB-5.5+ are quite different MariaDB solution could not borrow any code from the MySQL-8.0 solution.
* | | | MDEV-17363 - Compressed columns cannot be restored from dumpAlexander Barkov2019-06-181-35/+73
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In collaboration with Sergey Vojtovich <svoj@mariadb.org> The COMPRESSED clause is now a part of the data type and goes immediately after the data type and length, but before the CHARACTER SET clause, and before column attributes such as DEFAULT, COLLATE, ON UPDATE, SYSTEM VERSIONING, engine specific column attributes. In the old reduction, the COMPRESSED clause was a column attribute. New syntax: <varchar or text data type> <length> <compression> <character set> <column attributes> <varbinary or blob data type> <length> <compression> <column attributes> New syntax examples: VARCHAR(1000) COMPRESSED CHARACTER SET latin1 DEFAULT '' BLOB COMPRESSED DEFAULT '' Deprecate syntax examples: VARCHAR(1000) CHARACTER SET latin1 COMPRESSED DEFAULT '' TEXT CHARACTER SET latin1 DEFAULT '' COMPRESSED VARBINARY(1000) DEFAULT '' COMPRESSED As a side effect: - COMPRESSED is not valid as an SP label name in SQL/PSM routines any more (but it's still valid as an SP label name in sql_mode=ORACLE) - COMPRESSED is now allowed in combination with GENERATED ALWAYS AS: TEXT COMPRESSED GENERATED ALWAYS AS REPEAT('a',1000)
* | | | Merge branch '10.2' into 10.3Oleksandr Byelkin2019-06-141-45/+22
|\ \ \ \ | |/ / /
| * | | Merge 10.1 into 10.2Marko Mäkelä2019-06-121-33/+19
| |\ \ \ | | |/ /
| | * | MDEV-19653 Add class Sql_cmd_create_tableAlexander Barkov2019-05-311-33/+19
| | | |
* | | | MDEV-18136 Server crashes in Item_func_dyncol_create::prepare_argumentsAleksey Midenkov2019-05-201-6/+1
| | | | | | | | | | | | | | | | [Closes tempesta-tech/mariadb#572]
* | | | MDEV-16872 Add CAST(expr AS FLOAT)Alexander Barkov2019-05-161-0/+1
| | | |