Commit graph

187 commits

Author SHA1 Message Date
Sergei Golubchik
57e0da50bb Merge branch '10.2' into 10.3 2018-09-28 16:37:06 +02:00
Oleksandr Byelkin
28f08d3753 Merge branch '10.1' into 10.2 2018-09-14 08:47:22 +02:00
Oleksandr Byelkin
31081593aa Merge branch '11.0' into 10.1 2018-09-06 22:45:19 +02:00
Sergei Golubchik
9180e8666b MDEV-16465 Invalid (old?) table or database name or hang in ha_innobase::delete_table and log semaphore wait upon concurrent DDL with foreign keys
ALTER TABLE locks the table with TL_READ_NO_INSERT, to prevent the
source table modifications while it's being copied. But there's an
indirect way of modifying a table, via cascade FK actions.

After previous commits, an attempt to modify an FK parent table
will cause FK children to be prelocked, so the table-being-altered
cannot be modified by a cascade FK action, because ALTER holds a
lock and prelocking will wait.

But if a new FK is being added by this very ALTER, then the target
table is not locked yet (it's a temporary table). So, we have to
lock FK parents explicitly.
2018-09-04 09:49:53 +02:00
Alexey Botchkov
63ad6a9e1a MDEV-15890 Strange error message if you try to FLUSH TABLES <view> after LOCK TABLES <view>.
Check if the argument of the FLUSH TABLE is a VIEW and handle it
accordingly.
2018-09-02 09:24:33 +04:00
Marko Mäkelä
f418661efa Merge 10.2 into 10.3 2018-07-23 18:56:52 +03:00
Sachin
9827c5e103 MDEV-16192 Table 't' is specified twice, both as a target for 'CREATE' and...
as a separate source for data

Actually MDEV-15867 and MDEV-16192 are same, Slave adds "or replace" to create
table stmt. So create table t1 is create or replace on slave. So this bug
is not because of replication, We can get this bug on general server if we
manually add or replace to create query.

Problem:- So if we try to create table t1 (same name as of temp table t1 ) via
   CREATE or replace TABLE t AS SELECT * FROM t;
Since in this query we are creating table from select * from t1 , we call
unique_table function to see whether if source and destination table are same.
But there is one issue unique_table does not account if source table is tmp table
in this case source and destination table can be same.

Solution:- We will change find_dup_table to not to look for temp table if
CHECK_DUP_SKIP_TEMP_TABLE flag is on.
2018-07-18 20:58:59 +05:30
Sergei Golubchik
4ec8598c1d Merge branch 'github/10.2' into 10.3 2018-05-22 11:47:09 +02:00
Sergei Golubchik
ff1d10ef9c Merge branch '10.1' into 10.2 2018-05-20 20:25:35 +02:00
Sergei Golubchik
91dfb6141f Merge branch '10.0' into 10.1 2018-05-19 22:05:55 +02:00
Marko Mäkelä
4c7608aeb1 Merge 10.2 into 10.3 2018-05-17 08:42:53 +03:00
Monty
ef295c31e3 MDEV-11129 CREATE OR REPLACE TABLE t1 AS SELECT spfunc() crashes if spfunc() references t1
Fixed by extending unique_table() with a flag to not allow usage of
the replaced table.

I also cleaned up find_dup_table() to not use goto next.
I also added more comments to the code in find_dup_table()
2018-05-16 21:51:46 +03:00
Varun Gupta
6f4534e622 MDEV-14695: Assertion `n < m_size' failed in Bounds_checked_array<Element_type>::operator
In this issue we hit the assert because we are adding addition fields to the field JOIN::all_fields list. This
is done because  HEAP tables can't index BIT fields so  we need to use an additional hidden field for grouping because later it will be
converted to a LONG field. Original field will remain of the BIT type and will be returned. This happens when we convert DISTINCT to
GROUP BY.

The solution is to take into account the number of such hidden fields that would be added to the field
JOIN::all_fields list while calculating the size of the ref_pointer_array.
2018-05-16 11:40:11 +05:30
Alexey Botchkov
e06c029849 MDEV-15465 Server crash or ASAN heap-use-after-free in Item_func_match::cleanup upon using FT search with partitioning.
Partition engine FT keys are implemented in such a way that
the FT function's cleanup() methods use table's internals.
So calling them after close_thread_tables is unsafe.
2018-05-15 14:10:19 +04:00
Marko Mäkelä
7396dfcca7 Merge 10.2 into 10.3 2018-04-24 20:59:57 +03:00
Marko Mäkelä
4cd7979c56 Merge 10.1 into 10.2 2018-04-24 09:39:45 +03:00
Marko Mäkelä
9c34a4124d Merge 10.0 into 10.1 2018-04-24 09:26:40 +03:00
Sergei Golubchik
587568b72a Merge branch '5.5' into 10.0 2018-04-20 14:33:24 +02:00
Sergei Golubchik
1a019d0801 Merge branch 'mysql/5.5' into 5.5 2018-04-19 22:31:26 +02:00
Nisha Gopalakrishnan
c0b4d74b52 BUG#27216817: INNODB: FAILING ASSERTION:
PREBUILT->TABLE->N_MYSQL_HANDLES_OPENED == 1

ANALYSIS:
=========

Adding unique index to a InnoDB table which is locked as
mutliple instances may trigger an InnoDB assert.

When we add a primary key or an unique index, we need to
drop the original table and rebuild all indexes. InnoDB
expects that only the instance of the table that is being
rebuilt, is open during the process. In the current
scenario we have opened multiple instances of the table.
This triggers an assert during table rebuild.
'Locked_tables_list' encapsulates a list of all
instances of tables locked by LOCK TABLES statement.

FIX:
===
We are now temporarily closing all the instances of the
table except the one which is being altered and later
reopen them via Locked_tables_list::reopen_tables().
2018-02-26 14:37:39 +05:30
Sergei Golubchik
103715d0fa cleanup: renames
enum_mark_columns -> enum_column_usage
mark_used_columns -> column_usage

further commits will replace MARK_COLUMN_NONE with
COLUMN_READ and COLUMN_WRITE that convey the intention
without causing columns to be marked
2018-02-12 22:49:10 +01:00
Vladislav Vaintroub
6c279ad6a7 MDEV-15091 : Windows, 64bit: reenable and fix warning C4267 (conversion from 'size_t' to 'type', possible loss of data)
Handle string length as size_t, consistently (almost always:))
Change function prototypes to accept size_t, where in the past
ulong or uint were used. change local/member variables to size_t
when appropriate.

This fix excludes rocksdb, spider,spider, sphinx and connect for now.
2018-02-06 12:55:58 +00:00
Monty
a7e352b54d Changed database, tablename and alias to be LEX_CSTRING
This was done in, among other things:
- thd->db and thd->db_length
- TABLE_LIST tablename, db, alias and schema_name
- Audit plugin database name
- lex->db
- All db and table names in Alter_table_ctx
- st_select_lex db

Other things:
- Changed a lot of functions to take const LEX_CSTRING* as argument
  for db, table_name and alias. See init_one_table() as an example.
- Changed some function arguments from LEX_CSTRING to const LEX_CSTRING
- Changed some lists from LEX_STRING to LEX_CSTRING
- threads_mysql.result changed because process list_db wasn't always
  correctly updated
- New append_identifier() function that takes LEX_CSTRING* as arguments
- Added new element tmp_buff to Alter_table_ctx to separate temp name
  handling from temporary space
- Ensure we store the length after my_casedn_str() of table/db names
- Removed not used version of rename_table_in_stat_tables()
- Changed Natural_join_column::table_name and db_name() to never return
  NULL (used for print)
- thd->get_db() now returns db as a printable string (thd->db.str or "")
2018-01-30 21:33:55 +02:00
Monty
9cc7789e90 MDEV 13679 Enabled sequences to be used in DEFAULT
Other changes done to get this to work:
- Added 'internal_tables' to TABLE object to list which sequence tables
  is needed to use the table.
- Mark any expression using DEFAULT() with LEX->default_used.
  This is needed when deciding if we should open internal sequence
  tables when a table is opened (we don't need to open sequence tables
  if the main table is only used with SELECT).
- Create_and_open_temporary_table() can now also open all internal
  sequence tables.
- Added option MYSQL_LOCK_USE_MALLOC to mysql_lock_tables()
  to force memory allocation to be used with malloc instead of
  memroot.
- Added flag to MYSQL_LOCK to remember if allocation was done with
  malloc or memroot (makes code simpler and safer).
- init_one_table_for_prelocking() now takes argument for what lock to
  use instead of it's a routine or something else.
- Renamed prelocking placeholders to make them more understandable as
  they are now used in more code.
- Changed test in check_lock_and_start_stmt() if found table has correct
  locks. The old test didn't work for tables that has lock
  TL_WRITE_ALLOW_WRITE, which is what sequence tables are using.
- Added VCOL_NOT_VIRTUAL option to ensure that sequence functions can't
  be used with virtual columns
- More sequence tests
2017-12-22 14:56:58 +02:00
Alexander Barkov
003cb2f424 Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext 2017-10-30 16:42:46 +04:00
Sergei Golubchik
e0a1c745ec Merge branch '10.1' into 10.2 2017-10-24 14:53:18 +02:00
Sergei Golubchik
9d2e2d7533 Merge branch '10.0' into 10.1 2017-10-22 13:03:41 +02:00
Sergei Golubchik
da4503e956 Merge branch '5.5' into 10.0 2017-10-18 15:14:39 +02:00
Oleksandr Byelkin
235b68299b MDEV-9619: Assertion `null_ref_table' failed in virtual table_map Item_direct_view_ref::used_tables() const on 2nd execution of PS
Refer left expression indirectly in case it changes from execution to execution.
2017-10-13 19:32:38 +02:00
Monty
5a759d31f7 Changing field::field_name and Item::name to LEX_CSTRING
Benefits of this patch:
- Removed a lot of calls to strlen(), especially for field_string
- Strings generated by parser are now const strings, less chance of
  accidently changing a string
- Removed a lot of calls with LEX_STRING as parameter (changed to pointer)
- More uniform code
- Item::name_length was not kept up to date. Now fixed
- Several bugs found and fixed (Access to null pointers,
  access of freed memory, wrong arguments to printf like functions)
- Removed a lot of casts from (const char*) to (char*)

Changes:
- This caused some ABI changes
  - lex_string_set now uses LEX_CSTRING
  - Some fucntions are now taking const char* instead of char*
- Create_field::change and after changed to LEX_CSTRING
- handler::connect_string, comment and engine_name() changed to LEX_CSTRING
- Checked printf() related calls to find bugs. Found and fixed several
  errors in old code.
- A lot of changes from LEX_STRING to LEX_CSTRING, especially related to
  parsing and events.
- Some changes from LEX_STRING and LEX_STRING & to LEX_CSTRING*
- Some changes for char* to const char*
- Added printf argument checking for my_snprintf()
- Introduced null_clex_str, star_clex_string, temp_lex_str to simplify
  code
- Added item_empty_name and item_used_name to be able to distingush between
  items that was given an empty name and items that was not given a name
  This is used in sql_yacc.yy to know when to give an item a name.
- select table_name."*' is not anymore same as table_name.*
- removed not used function Item::rename()
- Added comparision of item->name_length before some calls to
  my_strcasecmp() to speed up comparison
- Moved Item_sp_variable::make_field() from item.h to item.cc
- Some minimal code changes to avoid copying to const char *
- Fixed wrong error message in wsrep_mysql_parse()
- Fixed wrong code in find_field_in_natural_join() where real_item() was
  set when it shouldn't
- ER_ERROR_ON_RENAME was used with extra arguments.
- Removed some (wrong) ER_OUTOFMEMORY, as alloc_root will already
  give the error.

TODO:
- Check possible unsafe casts in plugin/auth_examples/qa_auth_interface.c
- Change code to not modify LEX_CSTRING for database name
  (as part of lower_case_table_names)
2017-04-23 22:35:46 +03:00
Alexander Barkov
46d076d67a MDEV-10577 sql_mode=ORACLE: %TYPE in variable declarations 2017-04-05 15:02:54 +04:00
Monty
5f0c31f928 MDEV-11597 Assertion when doing select from virtual column with impossible value
- Changed error handlers interface so that they can change error level in
  the handler
- Give warnings and errors when calculating virtual columns
- On insert/update error is fatal in strict mode.
- SELECT and DELETE will only give a warning if a virtual field generates an error
- Added VCOL_UPDATE_FOR_DELETE and VCOL_UPDATE_INDEX_FOR_REPLACE to be able to
  easily detect in update_virtual_fields() if we should use an error
  handler to mask errors or not.
2017-01-11 09:19:45 +02:00
Sergei Golubchik
54ab7db733 cleanup: remove now-unused TABLE::merge_keys 2016-12-12 20:27:37 +01:00
Sergei Golubchik
9a3ec79b53 cleanup: TABLE::update_virtual_fields
Make update_virtual_fields() a method of TABLE, to be consistent
with TABLE::update_default_fields().
2016-12-12 20:27:33 +01:00
Monty
8be53a389c MDEV-6112 multiple triggers per table
This is similar to MysQL Worklog 3253, but with
a different implementation. The disk format and
SQL syntax is identical with MySQL 5.7.

Fetures supported:
- "Any" ammount of any trigger
- Supports FOLLOWS and PRECEDES to be
  able to put triggers in a certain execution order.

Implementation details:
- Class Trigger added to hold information about a trigger.
  Before this trigger information was stored in a set of lists in
  Table_triggers_list and in Table_triggers_list::bodies
- Each Trigger has a next field that poinst to the next Trigger with the
  same action and time.
- When accessing a trigger, we now always access all linked triggers
- The list are now only used to load and save trigger files.
- MySQL trigger test case (trigger_wl3253) added and we execute these
  identically.
- Even more gracefully handling of wrong trigger files than before. This
  is useful if a trigger file uses functions or syntax not provided by
  the server.
- Each trigger now has a "Created" field that shows when the trigger was
  created, with 2 decimals.

Other comments:
- Many of the changes in test files was done because of the new "Created"
  field in the trigger file. This shows up in SHOW ... TRIGGER and when
  using information_schema.trigger.
- Don't check if all memory is released if on uses --gdb;  This is needed
  to be able to get a list from safemalloc of not freed memory while
  debugging.
- Added option to trim_whitespace() to know how many prefix characters
  was skipped.
- Changed a few ulonglong sql_mode to sql_mode_t, to find some wrong usage
  of sql_mode.
2016-10-05 01:11:07 +03:00
Sergei Golubchik
f93a2a3b3b various cleanups
* remove a confusing method name - Field::set_default_expression()
* remove handler::register_columns_for_write()
* rename stuff
* add asserts
* remove unlikely unlikely
* remove redundant if() conditions
* fix mark_unsupported_function() to report the most important violation
* don't scan vfield list for default values (vfields don't have defaults)
* move handling for DROP CONSTRAINT IF EXIST where it belongs
* don't protect engines from Alter_inplace_info::ALTER_ADD_CONSTRAINT
* comments
2016-06-30 11:43:02 +02:00
Michael Widenius
db7edfed17 MDEV-7563 Support CHECK constraint as in (or close to) SQL Standard
MDEV-10134 Add full support for DEFAULT

- Added support for using tables with MySQL 5.7 virtual fields,
  including MySQL 5.7 syntax
- Better error messages also for old cases
- CREATE ... SELECT now also updates timestamp columns
- Blob can now have default values
- Added new system variable "check_constraint_checks", to turn of
  CHECK constraint checking if needed.
- Removed some engine independent tests in suite vcol to only test myisam
- Moved some tests from 'include' to 't'. Should some day be done for all tests.
- FRM version increased to 11 if one uses virtual fields or constraints
- Changed to use a bitmap to check if a field has got a value, instead of
  setting HAS_EXPLICIT_VALUE bit in field flags
- Expressions can now be up to 65K in total
- Ensure we are not refering to uninitialized fields when handling virtual fields or defaults
- Changed check_vcol_func_processor() to return a bitmap of used types
- Had to change some functions that calculated cached value in fix_fields to do
  this in val() or getdate() instead.
- store_now_in_TIME() now takes a THD argument
- fill_record() now updates default values
- Add a lookahead for NOT NULL, to be able to handle DEFAULT 1+1 NOT NULL
- Automatically generate a name for constraints that doesn't have a name
- Added support for ALTER TABLE DROP CONSTRAINT
- Ensure that partition functions register virtual fields used. This fixes
  some bugs when using virtual fields in a partitioning function
2016-06-30 11:43:02 +02:00
Nirbhay Choubey
7305be2f7e MDEV-5535: Cannot reopen temporary table
mysqld maintains a list of TABLE objects for all temporary
tables created within a session in THD. Here each table is
represented by a TABLE object.

A query referencing a particular temporary table for more
than once, however, failed with ER_CANT_REOPEN_TABLE error
because a TABLE_SHARE was allocate together with the TABLE,
so temporary tables always had only one TABLE per TABLE_SHARE.

This patch lift this restriction by separating TABLE and
TABLE_SHARE objects and storing TABLE_SHAREs for temporary
tables in a list in THD, and TABLEs in a list within their
respective TABLE_SHAREs.
2016-06-10 18:39:43 -04:00
Sergey Vojtovich
7ecb304996 Code cleanups
- unused TABLE_SHARE::deleting and TABLE_LIST::deleting flags were removed
- kill_delayed_threads_for_table() and intern_close_table() are now private
  methods of table cache
- removed free_share flag of closefrm(): it was never used for temporary
  tables and was rarely useful for regular tables
2016-06-10 17:37:12 +04:00
Monty
9c846373f0 Merge commit 'd5822a3ad0657040114cdc185c6387b9eb3a12b2' into 10.2 2016-04-28 16:59:33 +03:00
Igor Babaev
5ff4b21e02 Fixed bug mdev-9897.
This bug revealed a serious problem: if the same partition list
was used in two window specifications then the temporary table created
to calculate window functions contained fields for two identical
partitions. This problem was fixed as well.
2016-04-14 00:47:28 -07:00
Monty
293cb04959 MDEV-9621 INSERT DELAYED fails on insert for tables with many columns
This fix also fixes a connection hang when trying to do INSERT DELAYED to a crashed table.

Added crash_mysqld.inc to allow easy crash+restart of mysqld
2016-04-07 19:31:10 +03:00
Sergei Petrunia
2bd4dc38e0 Merge branch '10.2' into bb-10.2-mdev9543 2016-03-28 22:18:38 +03:00
Monty
260dd476b0 Removed TABLE->sort to make it possible to have multiple active calls to
filesort and init_read_record() for the same table.
This will simplify code for WINDOW FUNCTIONS (MDEV-6115)

- Filesort_info renamed to SORT_INFO and moved to filesort.h
- filesort now returns SORT_INFO
- init_read_record() now takes a SORT_INFO parameter.
- unique declaration is moved to uniques.h
- subselect caching of buffers is now more explicit than before
- filesort_buffer is now reusable even if rec_length has changed.
- filsort_free_buffers() and free_io_cache() calls are removed
- Remove one malloc() when using get_addon_fields()

Other things:
- Added --debug-assert-on-not-freed-memory option to make it easier to
  debug some not-freed-memory issues.
2016-03-22 23:44:52 +02:00
Sergey Vojtovich
3692bd3238 MDEV-9488 - Table cache cleanups
Cleanup now unused arguments of tdc_open_view().
2016-02-26 18:36:31 +04:00
Igor Babaev
2cfc450bf7 This is the consolidated patch for mdev-8646:
"Re-factor the code for post-join operations".

The patch mainly contains the code ported from mysql-5.6 and
created for two essential architectural changes:
1. WL#5558: Resolve ORDER BY execution method at the optimization stage
2. WL#6071: Inline tmp tables into the nested loops algorithm

The first task was implemented for mysql-5.6 by Ole John Aske.
It allows to make all decisions on ORDER BY operation at the optimization
stage.

The second task implemented for mysql-5.6 by Evgeny Potemkin adds JOIN_TAB
nodes for post-join operations that require temporary tables. It allows
to execute these operations within the nested loops algorithm that used to
be used before this task only for join queries. Besides these task moves
all planning on the execution of these operations from the execution phase
to the optimization phase.

Some other re-factoring changes of mysql-5.6 were pulled in, mainly because
it was easier to pull them in than roll them back. In particular all
changes concerning Ref_ptr_array were incorporated.

The port required some changes in the MariaDB code that concerned the
functionality of EXPLAIN and ANALYZE. This was done mainly by Sergey
Petrunia.
2016-02-09 12:35:59 -08:00
Sergei Golubchik
0686c34d22 MDEV-8605 MariaDB not use DEFAULT value even when inserted NULL for NOT NULLABLE column
NOT NULL constraint must be checked *after* the BEFORE triggers.
That is for INSERT and UPDATE statements even NOT NULL fields
must be able to store a NULL temporarily at least while
BEFORE INSERT/UPDATE triggers are running.
2015-12-21 21:30:54 +01:00
Sergei Golubchik
beded7d9c9 Merge branch '10.0' into 10.1 2015-11-19 15:52:14 +01:00
Sergei Golubchik
fb8713385f remove unneded #include's that had a dubious explanation 2015-10-24 19:58:34 +02:00
Sergey Vojtovich
4d1ccc4289 MDEV-7951 - sql_alloc() takes 0.25% in OLTP RO
sql_alloc() has additional costs compared to direct mem_root allocation:
- function call: it is defined in a separate translation unit and can't be
  inlined
- it needs to call pthread_getspecific() to get THD::mem_root

It is called dozens of times implicitely at least by:
- List<>::push_back()
- List<>::push_front()
- new (for Sql_alloc derived classes)
- sql_memdup()

Replaced lots of implicit sql_alloc() calls with direct mem_root allocation,
passing through THD pointer whenever it is needed.

Number of sql_alloc() calls reduced 345 -> 41 per OLTP RO transaction.
pthread_getspecific() overhead dropped 0.76 -> 0.59
sql_alloc() overhed dropped 0.25 -> 0.06
2015-05-13 10:43:14 +04:00