2009-10-30 19:50:56 +01:00
|
|
|
/*
|
2009-12-03 12:19:05 +01:00
|
|
|
Copyright (c) 2008-2009, Patrick Galbraith & Antony Curtis
|
2022-04-06 09:06:39 +02:00
|
|
|
Copyright (c) 2020, 2022, MariaDB Corporation.
|
2009-10-30 19:50:56 +01:00
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions are
|
|
|
|
met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
|
|
|
|
* Neither the name of Patrick Galbraith nor the names of its
|
|
|
|
contributors may be used to endorse or promote products derived from
|
|
|
|
this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
|
|
|
|
FederatedX Pluggable Storage Engine
|
|
|
|
|
|
|
|
ha_federatedx.cc - FederatedX Pluggable Storage Engine
|
|
|
|
Patrick Galbraith, 2008
|
|
|
|
|
|
|
|
This is a handler which uses a foreign database as the data file, as
|
|
|
|
opposed to a handler like MyISAM, which uses .MYD files locally.
|
|
|
|
|
|
|
|
How this handler works
|
|
|
|
----------------------------------
|
|
|
|
Normal database files are local and as such: You create a table called
|
|
|
|
'users', a file such as 'users.MYD' is created. A handler reads, inserts,
|
|
|
|
deletes, updates data in this file. The data is stored in particular format,
|
|
|
|
so to read, that data has to be parsed into fields, to write, fields have to
|
|
|
|
be stored in this format to write to this data file.
|
|
|
|
|
|
|
|
With FederatedX storage engine, there will be no local files
|
|
|
|
for each table's data (such as .MYD). A foreign database will store
|
|
|
|
the data that would normally be in this file. This will necessitate
|
|
|
|
the use of MySQL client API to read, delete, update, insert this
|
|
|
|
data. The data will have to be retrieve via an SQL call "SELECT *
|
|
|
|
FROM users". Then, to read this data, it will have to be retrieved
|
|
|
|
via mysql_fetch_row one row at a time, then converted from the
|
|
|
|
column in this select into the format that the handler expects.
|
|
|
|
|
|
|
|
The create table will simply create the .frm file, and within the
|
|
|
|
"CREATE TABLE" SQL, there SHALL be any of the following :
|
|
|
|
|
|
|
|
connection=scheme://username:password@hostname:port/database/tablename
|
|
|
|
connection=scheme://username@hostname/database/tablename
|
|
|
|
connection=scheme://username:password@hostname/database/tablename
|
|
|
|
connection=scheme://username:password@hostname/database/tablename
|
|
|
|
|
|
|
|
- OR -
|
|
|
|
|
|
|
|
As of 5.1 federatedx now allows you to use a non-url
|
|
|
|
format, taking advantage of mysql.servers:
|
|
|
|
|
|
|
|
connection="connection_one"
|
|
|
|
connection="connection_one/table_foo"
|
|
|
|
|
|
|
|
An example would be:
|
|
|
|
|
|
|
|
connection=mysql://username:password@hostname:port/database/tablename
|
|
|
|
|
|
|
|
or, if we had:
|
|
|
|
|
|
|
|
create server 'server_one' foreign data wrapper 'mysql' options
|
|
|
|
(HOST '127.0.0.1',
|
|
|
|
DATABASE 'db1',
|
|
|
|
USER 'root',
|
|
|
|
PASSWORD '',
|
|
|
|
PORT 3306,
|
|
|
|
SOCKET '',
|
|
|
|
OWNER 'root');
|
|
|
|
|
|
|
|
CREATE TABLE federatedx.t1 (
|
|
|
|
`id` int(20) NOT NULL,
|
|
|
|
`name` varchar(64) NOT NULL default ''
|
|
|
|
)
|
|
|
|
ENGINE="FEDERATEDX" DEFAULT CHARSET=latin1
|
|
|
|
CONNECTION='server_one';
|
|
|
|
|
|
|
|
So, this will have been the equivalent of
|
|
|
|
|
|
|
|
CONNECTION="mysql://root@127.0.0.1:3306/db1/t1"
|
|
|
|
|
|
|
|
Then, we can also change the server to point to a new schema:
|
|
|
|
|
|
|
|
ALTER SERVER 'server_one' options(DATABASE 'db2');
|
|
|
|
|
|
|
|
All subsequent calls will now be against db2.t1! Guess what? You don't
|
|
|
|
have to perform an alter table!
|
|
|
|
|
|
|
|
This connecton="connection string" is necessary for the handler to be
|
|
|
|
able to connect to the foreign server, either by URL, or by server
|
|
|
|
name.
|
|
|
|
|
|
|
|
|
|
|
|
The basic flow is this:
|
|
|
|
|
|
|
|
SQL calls issues locally ->
|
|
|
|
mysql handler API (data in handler format) ->
|
|
|
|
mysql client API (data converted to SQL calls) ->
|
|
|
|
foreign database -> mysql client API ->
|
|
|
|
convert result sets (if any) to handler format ->
|
|
|
|
handler API -> results or rows affected to local
|
|
|
|
|
|
|
|
What this handler does and doesn't support
|
|
|
|
------------------------------------------
|
|
|
|
* Tables MUST be created on the foreign server prior to any action on those
|
|
|
|
tables via the handler, first version. IMPORTANT: IF you MUST use the
|
|
|
|
federatedx storage engine type on the REMOTE end, MAKE SURE [ :) ] That
|
|
|
|
the table you connect to IS NOT a table pointing BACK to your ORIGNAL
|
|
|
|
table! You know and have heard the screaching of audio feedback? You
|
|
|
|
know putting two mirror in front of each other how the reflection
|
|
|
|
continues for eternity? Well, need I say more?!
|
|
|
|
* There will not be support for transactions.
|
|
|
|
* There is no way for the handler to know if the foreign database or table
|
|
|
|
has changed. The reason for this is that this database has to work like a
|
|
|
|
data file that would never be written to by anything other than the
|
|
|
|
database. The integrity of the data in the local table could be breached
|
|
|
|
if there was any change to the foreign database.
|
|
|
|
* Support for SELECT, INSERT, UPDATE , DELETE, indexes.
|
|
|
|
* No ALTER TABLE, DROP TABLE or any other Data Definition Language calls.
|
|
|
|
* Prepared statements will not be used in the first implementation, it
|
|
|
|
remains to to be seen whether the limited subset of the client API for the
|
|
|
|
server supports this.
|
|
|
|
* This uses SELECT, INSERT, UPDATE, DELETE and not HANDLER for its
|
|
|
|
implementation.
|
|
|
|
* This will not work with the query cache.
|
|
|
|
|
|
|
|
Method calls
|
|
|
|
|
|
|
|
A two column table, with one record:
|
|
|
|
|
|
|
|
(SELECT)
|
|
|
|
|
|
|
|
"SELECT * FROM foo"
|
|
|
|
ha_federatedx::info
|
|
|
|
ha_federatedx::scan_time:
|
|
|
|
ha_federatedx::rnd_init: share->select_query SELECT * FROM foo
|
|
|
|
ha_federatedx::extra
|
|
|
|
|
|
|
|
<for every row of data retrieved>
|
|
|
|
ha_federatedx::rnd_next
|
|
|
|
ha_federatedx::convert_row_to_internal_format
|
|
|
|
ha_federatedx::rnd_next
|
|
|
|
</for every row of data retrieved>
|
|
|
|
|
|
|
|
ha_federatedx::rnd_end
|
|
|
|
ha_federatedx::extra
|
|
|
|
ha_federatedx::reset
|
|
|
|
|
|
|
|
(INSERT)
|
|
|
|
|
|
|
|
"INSERT INTO foo (id, ts) VALUES (2, now());"
|
|
|
|
|
|
|
|
ha_federatedx::write_row
|
|
|
|
|
|
|
|
ha_federatedx::reset
|
|
|
|
|
|
|
|
(UPDATE)
|
|
|
|
|
|
|
|
"UPDATE foo SET ts = now() WHERE id = 1;"
|
|
|
|
|
|
|
|
ha_federatedx::index_init
|
|
|
|
ha_federatedx::index_read
|
|
|
|
ha_federatedx::index_read_idx
|
|
|
|
ha_federatedx::rnd_next
|
|
|
|
ha_federatedx::convert_row_to_internal_format
|
|
|
|
ha_federatedx::update_row
|
|
|
|
|
|
|
|
ha_federatedx::extra
|
|
|
|
ha_federatedx::extra
|
|
|
|
ha_federatedx::extra
|
|
|
|
ha_federatedx::external_lock
|
|
|
|
ha_federatedx::reset
|
|
|
|
|
|
|
|
|
|
|
|
How do I use this handler?
|
|
|
|
--------------------------
|
|
|
|
|
|
|
|
<insert text about plugin storage engine>
|
|
|
|
|
|
|
|
Next, to use this handler, it's very simple. You must
|
|
|
|
have two databases running, either both on the same host, or
|
|
|
|
on different hosts.
|
|
|
|
|
|
|
|
One the server that will be connecting to the foreign
|
|
|
|
host (client), you create your table as such:
|
|
|
|
|
|
|
|
CREATE TABLE test_table (
|
|
|
|
id int(20) NOT NULL auto_increment,
|
|
|
|
name varchar(32) NOT NULL default '',
|
|
|
|
other int(20) NOT NULL default '0',
|
|
|
|
PRIMARY KEY (id),
|
|
|
|
KEY name (name),
|
|
|
|
KEY other_key (other))
|
|
|
|
ENGINE="FEDERATEDX"
|
|
|
|
DEFAULT CHARSET=latin1
|
|
|
|
CONNECTION='mysql://root@127.0.0.1:9306/federatedx/test_federatedx';
|
|
|
|
|
|
|
|
Notice the "COMMENT" and "ENGINE" field? This is where you
|
|
|
|
respectively set the engine type, "FEDERATEDX" and foreign
|
|
|
|
host information, this being the database your 'client' database
|
|
|
|
will connect to and use as the "data file". Obviously, the foreign
|
|
|
|
database is running on port 9306, so you want to start up your other
|
|
|
|
database so that it is indeed on port 9306, and your federatedx
|
|
|
|
database on a port other than that. In my setup, I use port 5554
|
|
|
|
for federatedx, and port 5555 for the foreign database.
|
|
|
|
|
|
|
|
Then, on the foreign database:
|
|
|
|
|
|
|
|
CREATE TABLE test_table (
|
|
|
|
id int(20) NOT NULL auto_increment,
|
|
|
|
name varchar(32) NOT NULL default '',
|
|
|
|
other int(20) NOT NULL default '0',
|
|
|
|
PRIMARY KEY (id),
|
|
|
|
KEY name (name),
|
|
|
|
KEY other_key (other))
|
|
|
|
ENGINE="<NAME>" <-- whatever you want, or not specify
|
|
|
|
DEFAULT CHARSET=latin1 ;
|
|
|
|
|
|
|
|
This table is exactly the same (and must be exactly the same),
|
|
|
|
except that it is not using the federatedx handler and does
|
|
|
|
not need the URL.
|
|
|
|
|
|
|
|
|
|
|
|
How to see the handler in action
|
|
|
|
--------------------------------
|
|
|
|
|
|
|
|
When developing this handler, I compiled the federatedx database with
|
|
|
|
debugging:
|
|
|
|
|
|
|
|
./configure --with-federatedx-storage-engine
|
|
|
|
--prefix=/home/mysql/mysql-build/federatedx/ --with-debug
|
|
|
|
|
|
|
|
Once compiled, I did a 'make install' (not for the purpose of installing
|
|
|
|
the binary, but to install all the files the binary expects to see in the
|
|
|
|
diretory I specified in the build with --prefix,
|
|
|
|
"/home/mysql/mysql-build/federatedx".
|
|
|
|
|
|
|
|
Then, I started the foreign server:
|
|
|
|
|
|
|
|
/usr/local/mysql/bin/mysqld_safe
|
|
|
|
--user=mysql --log=/tmp/mysqld.5555.log -P 5555
|
|
|
|
|
|
|
|
Then, I went back to the directory containing the newly compiled mysqld,
|
|
|
|
<builddir>/sql/, started up gdb:
|
|
|
|
|
|
|
|
gdb ./mysqld
|
|
|
|
|
|
|
|
Then, withn the (gdb) prompt:
|
2011-12-15 22:07:58 +01:00
|
|
|
(gdb) run --gdb --port=5554 --socket=/tmp/mysqld.5554 --skip-innodb --debug-dbug
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
Next, I open several windows for each:
|
|
|
|
|
|
|
|
1. Tail the debug trace: tail -f /tmp/mysqld.trace|grep ha_fed
|
|
|
|
2. Tail the SQL calls to the foreign database: tail -f /tmp/mysqld.5555.log
|
|
|
|
3. A window with a client open to the federatedx server on port 5554
|
|
|
|
4. A window with a client open to the federatedx server on port 5555
|
|
|
|
|
|
|
|
I would create a table on the client to the foreign server on port
|
|
|
|
5555, and then to the federatedx server on port 5554. At this point,
|
|
|
|
I would run whatever queries I wanted to on the federatedx server,
|
|
|
|
just always remembering that whatever changes I wanted to make on
|
|
|
|
the table, or if I created new tables, that I would have to do that
|
|
|
|
on the foreign server.
|
|
|
|
|
|
|
|
Another thing to look for is 'show variables' to show you that you have
|
|
|
|
support for federatedx handler support:
|
|
|
|
|
|
|
|
show variables like '%federat%'
|
|
|
|
|
|
|
|
and:
|
|
|
|
|
|
|
|
show storage engines;
|
|
|
|
|
|
|
|
Both should display the federatedx storage handler.
|
|
|
|
|
|
|
|
|
|
|
|
Testing
|
|
|
|
-------
|
|
|
|
|
|
|
|
Testing for FederatedX as a pluggable storage engine for
|
|
|
|
now is a manual process that I intend to build a test
|
|
|
|
suite that works for all pluggable storage engines.
|
|
|
|
|
|
|
|
How to test
|
|
|
|
|
|
|
|
1. cp fed.dat /tmp
|
|
|
|
(make sure you have access to "test". Use a user that has
|
|
|
|
super privileges for now)
|
|
|
|
2. mysql -f -u root test < federated.test > federated.myresult 2>&1
|
|
|
|
3. diff federated.result federated.myresult (there _should_ be no differences)
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2011-04-25 17:22:25 +02:00
|
|
|
#define MYSQL_SERVER 1
|
2014-10-02 11:57:40 +02:00
|
|
|
#include <my_global.h>
|
2009-10-30 19:50:56 +01:00
|
|
|
#include <mysql/plugin.h>
|
2022-09-12 14:39:12 +02:00
|
|
|
#include <mysql.h>
|
2011-04-25 17:22:25 +02:00
|
|
|
#include "ha_federatedx.h"
|
|
|
|
#include "sql_servers.h"
|
|
|
|
#include "sql_analyse.h" // append_escaped()
|
|
|
|
#include "sql_show.h" // append_identifier()
|
2018-05-14 10:47:13 +02:00
|
|
|
#include "tztime.h" // my_tz_find()
|
2018-10-09 11:36:09 +02:00
|
|
|
#include "sql_select.h"
|
2009-10-30 19:50:56 +01:00
|
|
|
|
2011-07-02 22:12:12 +02:00
|
|
|
#ifdef I_AM_PARANOID
|
|
|
|
#define MIN_PORT 1023
|
|
|
|
#else
|
|
|
|
#define MIN_PORT 0
|
|
|
|
#endif
|
|
|
|
|
2009-10-30 19:50:56 +01:00
|
|
|
/* Variables for federatedx share methods */
|
2011-04-25 17:22:25 +02:00
|
|
|
static HASH federatedx_open_tables; // To track open tables
|
|
|
|
static HASH federatedx_open_servers; // To track open servers
|
2011-07-13 21:10:18 +02:00
|
|
|
mysql_mutex_t federatedx_mutex; // To init the hash
|
2009-10-30 19:50:56 +01:00
|
|
|
const char ident_quote_char= '`'; // Character for quoting
|
|
|
|
// identifiers
|
|
|
|
const char value_quote_char= '\''; // Character for quoting
|
|
|
|
// literals
|
|
|
|
static const int bulk_padding= 64; // bytes "overhead" in packet
|
|
|
|
|
|
|
|
/* Variables used when chopping off trailing characters */
|
|
|
|
static const uint sizeof_trailing_comma= sizeof(", ") - 1;
|
|
|
|
static const uint sizeof_trailing_and= sizeof(" AND ") - 1;
|
|
|
|
static const uint sizeof_trailing_where= sizeof(" WHERE ") - 1;
|
|
|
|
|
2018-05-14 10:47:13 +02:00
|
|
|
static Time_zone *UTC= 0;
|
|
|
|
|
2009-10-30 19:50:56 +01:00
|
|
|
/* Static declaration for handerton */
|
|
|
|
static handler *federatedx_create_handler(handlerton *hton,
|
|
|
|
TABLE_SHARE *table,
|
|
|
|
MEM_ROOT *mem_root);
|
|
|
|
|
|
|
|
/* FederatedX storage engine handlerton */
|
|
|
|
|
|
|
|
static handler *federatedx_create_handler(handlerton *hton,
|
|
|
|
TABLE_SHARE *table,
|
|
|
|
MEM_ROOT *mem_root)
|
|
|
|
{
|
|
|
|
return new (mem_root) ha_federatedx(hton, table);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Function we use in the creation of our hash to get key */
|
|
|
|
|
2024-10-26 19:34:26 +02:00
|
|
|
static const uchar *federatedx_share_get_key(const void *share_,
|
|
|
|
size_t *length, my_bool)
|
2009-10-30 19:50:56 +01:00
|
|
|
{
|
2024-10-26 19:34:26 +02:00
|
|
|
auto share= static_cast<const FEDERATEDX_SHARE *>(share_);
|
2009-10-30 19:50:56 +01:00
|
|
|
*length= share->share_key_length;
|
2024-10-26 19:34:26 +02:00
|
|
|
return reinterpret_cast<const uchar *>(share->share_key);
|
2009-10-30 19:50:56 +01:00
|
|
|
}
|
|
|
|
|
2024-10-26 19:34:26 +02:00
|
|
|
static const uchar *federatedx_server_get_key(const void *server_,
|
|
|
|
size_t *length, my_bool)
|
2009-10-30 19:50:56 +01:00
|
|
|
{
|
2024-10-26 19:34:26 +02:00
|
|
|
auto server= static_cast<const FEDERATEDX_SERVER *>(server_);
|
2009-10-30 19:50:56 +01:00
|
|
|
*length= server->key_length;
|
2024-10-26 19:34:26 +02:00
|
|
|
return reinterpret_cast<const uchar *>(server->key);
|
2009-10-30 19:50:56 +01:00
|
|
|
}
|
|
|
|
|
2011-07-13 21:10:18 +02:00
|
|
|
#ifdef HAVE_PSI_INTERFACE
|
|
|
|
static PSI_mutex_key fe_key_mutex_federatedx, fe_key_mutex_FEDERATEDX_SERVER_mutex;
|
|
|
|
|
|
|
|
static PSI_mutex_info all_federated_mutexes[]=
|
|
|
|
{
|
|
|
|
{ &fe_key_mutex_federatedx, "federatedx", PSI_FLAG_GLOBAL},
|
|
|
|
{ &fe_key_mutex_FEDERATEDX_SERVER_mutex, "FEDERATED_SERVER::mutex", 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void init_federated_psi_keys(void)
|
|
|
|
{
|
|
|
|
const char* category= "federated";
|
|
|
|
int count;
|
|
|
|
|
|
|
|
if (PSI_server == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
count= array_elements(all_federated_mutexes);
|
|
|
|
PSI_server->register_mutex(category, all_federated_mutexes, count);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define init_federated_psi_keys() /* no-op */
|
|
|
|
#endif /* HAVE_PSI_INTERFACE */
|
|
|
|
|
2018-10-09 11:36:09 +02:00
|
|
|
handlerton* federatedx_hton;
|
|
|
|
|
|
|
|
static derived_handler*
|
|
|
|
create_federatedx_derived_handler(THD* thd, TABLE_LIST *derived);
|
2022-08-20 17:23:45 +02:00
|
|
|
|
2018-10-09 11:36:09 +02:00
|
|
|
static select_handler*
|
2022-08-20 17:23:45 +02:00
|
|
|
create_federatedx_select_handler(THD *thd, SELECT_LEX *sel_lex,
|
|
|
|
SELECT_LEX_UNIT *sel_unit);
|
|
|
|
static select_handler *
|
|
|
|
create_federatedx_unit_handler(THD *thd, SELECT_LEX_UNIT *sel_unit);
|
2009-10-30 19:50:56 +01:00
|
|
|
|
Changing all cost calculation to be given in milliseconds
This makes it easier to compare different costs and also allows
the optimizer to optimizer different storage engines more reliably.
- Added tests/check_costs.pl, a tool to verify optimizer cost calculations.
- Most engine costs has been found with this program. All steps to
calculate the new costs are documented in Docs/optimizer_costs.txt
- User optimizer_cost variables are given in microseconds (as individual
costs can be very small). Internally they are stored in ms.
- Changed DISK_READ_COST (was DISK_SEEK_BASE_COST) from a hard disk cost
(9 ms) to common SSD cost (400MB/sec).
- Removed cost calculations for hard disks (rotation etc).
- Changed the following handler functions to return IO_AND_CPU_COST.
This makes it easy to apply different cost modifiers in ha_..time()
functions for io and cpu costs.
- scan_time()
- rnd_pos_time() & rnd_pos_call_time()
- keyread_time()
- Enhanched keyread_time() to calculate the full cost of reading of a set
of keys with a given number of ranges and optional number of blocks that
need to be accessed.
- Removed read_time() as keyread_time() + rnd_pos_time() can do the same
thing and more.
- Tuned cost for: heap, myisam, Aria, InnoDB, archive and MyRocks.
Used heap table costs for json_table. The rest are using default engine
costs.
- Added the following new optimizer variables:
- optimizer_disk_read_ratio
- optimizer_disk_read_cost
- optimizer_key_lookup_cost
- optimizer_row_lookup_cost
- optimizer_row_next_find_cost
- optimizer_scan_cost
- Moved all engine specific cost to OPTIMIZER_COSTS structure.
- Changed costs to use 'records_out' instead of 'records_read' when
recalculating costs.
- Split optimizer_costs.h to optimizer_costs.h and optimizer_defaults.h.
This allows one to change costs without having to compile a lot of
files.
- Updated costs for filter lookup.
- Use a better cost estimate in best_extension_by_limited_search()
for the sorting cost.
- Fixed previous issues with 'filtered' explain column as we are now
using 'records_out' (min rows seen for table) to calculate filtering.
This greatly simplifies the filtering code in
JOIN_TAB::save_explain_data().
This change caused a lot of queries to be optimized differently than
before, which exposed different issues in the optimizer that needs to
be fixed. These fixes are in the following commits. To not have to
change the same test case over and over again, the changes in the test
cases are done in a single commit after all the critical change sets
are done.
InnoDB changes:
- Updated InnoDB to not divide big range cost with 2.
- Added cost for InnoDB (innobase_update_optimizer_costs()).
- Don't mark clustered primary key with HA_KEYREAD_ONLY. This will
prevent that the optimizer is trying to use index-only scans on
the clustered key.
- Disabled ha_innobase::scan_time() and ha_innobase::read_time() and
ha_innobase::rnd_pos_time() as the default engine cost functions now
works good for InnoDB.
Other things:
- Added --show-query-costs (\Q) option to mysql.cc to show the query
cost after each query (good when working with query costs).
- Extended my_getopt with GET_ADJUSTED_VALUE which allows one to adjust
the value that user is given. This is used to change cost from
microseconds (user input) to milliseconds (what the server is
internally using).
- Added include/my_tracker.h ; Useful include file to quickly test
costs of a function.
- Use handler::set_table() in all places instead of 'table= arg'.
- Added SHOW_OPTIMIZER_COSTS to sys variables. These are input and
shown in microseconds for the user but stored as milliseconds.
This is to make the numbers easier to read for the user (less
pre-zeros). Implemented in 'Sys_var_optimizer_cost' class.
- In test_quick_select() do not use index scans if 'no_keyread' is set
for the table. This is what we do in other places of the server.
- Added THD parameter to Unique::get_use_cost() and
check_index_intersect_extension() and similar functions to be able
to provide costs to called functions.
- Changed 'records' to 'rows' in optimizer_trace.
- Write more information to optimizer_trace.
- Added INDEX_BLOCK_FILL_FACTOR_MUL (4) and INDEX_BLOCK_FILL_FACTOR_DIV (3)
to calculate usage space of keys in b-trees. (Before we used numeric
constants).
- Removed code that assumed that b-trees has similar costs as binary
trees. Replaced with engine calls that returns the cost.
- Added Bitmap::find_first_bit()
- Added timings to join_cache for ANALYZE table (patch by Sergei Petrunia).
- Added records_init and records_after_filter to POSITION to remember
more of what best_access_patch() calculates.
- table_after_join_selectivity() changed to recalculate 'records_out'
based on the new fields from best_access_patch()
Bug fixes:
- Some queries did not update last_query_cost (was 0). Fixed by moving
setting thd->...last_query_cost in JOIN::optimize().
- Write '0' as number of rows for const tables with a matching row.
Some internals:
- Engine cost are stored in OPTIMIZER_COSTS structure. When a
handlerton is created, we also created a new cost variable for the
handlerton. We also create a new variable if the user changes a
optimizer cost for a not yet loaded handlerton either with command
line arguments or with SET
@@global.engine.optimizer_cost_variable=xx.
- There are 3 global OPTIMIZER_COSTS variables:
default_optimizer_costs The default costs + changes from the
command line without an engine specifier.
heap_optimizer_costs Heap table costs, used for temporary tables
tmp_table_optimizer_costs The cost for the default on disk internal
temporary table (MyISAM or Aria)
- The engine cost for a table is stored in table_share. To speed up
accesses the handler has a pointer to this. The cost is copied
to the table on first access. If one wants to change the cost one
must first update the global engine cost and then do a FLUSH TABLES.
This was done to be able to access the costs for an open table
without any locks.
- When a handlerton is created, the cost are updated the following way:
See sql/keycaches.cc for details:
- Use 'default_optimizer_costs' as a base
- Call hton->update_optimizer_costs() to override with the engines
default costs.
- Override the costs that the user has specified for the engine.
- One handler open, copy the engine cost from handlerton to TABLE_SHARE.
- Call handler::update_optimizer_costs() to allow the engine to update
cost for this particular table.
- There are two costs stored in THD. These are copied to the handler
when the table is used in a query:
- optimizer_where_cost
- optimizer_scan_setup_cost
- Simply code in best_access_path() by storing all cost result in a
structure. (Idea/Suggestion by Igor)
2022-08-11 12:05:23 +02:00
|
|
|
/*
|
|
|
|
Federated doesn't need costs.disk_read_ratio as everything is one a remote
|
|
|
|
server and nothing is cached locally
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void federatedx_update_optimizer_costs(OPTIMIZER_COSTS *costs)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Setting disk_read_ratios to 1.0, ensures we are using the costs
|
|
|
|
from rnd_pos_time() and scan_time()
|
|
|
|
*/
|
|
|
|
costs->disk_read_ratio= 0.0;
|
|
|
|
}
|
|
|
|
|
2009-10-30 19:50:56 +01:00
|
|
|
/*
|
|
|
|
Initialize the federatedx handler.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
federatedx_db_init()
|
|
|
|
p Handlerton
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
FALSE OK
|
|
|
|
TRUE Error
|
|
|
|
*/
|
|
|
|
|
|
|
|
int federatedx_db_init(void *p)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("federatedx_db_init");
|
2011-07-13 21:10:18 +02:00
|
|
|
init_federated_psi_keys();
|
2018-10-09 11:36:09 +02:00
|
|
|
federatedx_hton= (handlerton *)p;
|
2009-11-16 21:49:51 +01:00
|
|
|
/* Needed to work with old .frm files */
|
|
|
|
federatedx_hton->db_type= DB_TYPE_FEDERATED_DB;
|
2009-10-30 19:50:56 +01:00
|
|
|
federatedx_hton->savepoint_offset= sizeof(ulong);
|
|
|
|
federatedx_hton->close_connection= ha_federatedx::disconnect;
|
|
|
|
federatedx_hton->savepoint_set= ha_federatedx::savepoint_set;
|
|
|
|
federatedx_hton->savepoint_rollback= ha_federatedx::savepoint_rollback;
|
|
|
|
federatedx_hton->savepoint_release= ha_federatedx::savepoint_release;
|
|
|
|
federatedx_hton->commit= ha_federatedx::commit;
|
|
|
|
federatedx_hton->rollback= ha_federatedx::rollback;
|
2013-04-09 16:19:18 +02:00
|
|
|
federatedx_hton->discover_table_structure= ha_federatedx::discover_assisted;
|
2009-10-30 19:50:56 +01:00
|
|
|
federatedx_hton->create= federatedx_create_handler;
|
2020-06-22 22:14:25 +02:00
|
|
|
federatedx_hton->drop_table= [](handlerton *, const char*) { return -1; };
|
|
|
|
federatedx_hton->flags= HTON_ALTER_NOT_SUPPORTED;
|
2018-10-09 11:36:09 +02:00
|
|
|
federatedx_hton->create_derived= create_federatedx_derived_handler;
|
|
|
|
federatedx_hton->create_select= create_federatedx_select_handler;
|
Changing all cost calculation to be given in milliseconds
This makes it easier to compare different costs and also allows
the optimizer to optimizer different storage engines more reliably.
- Added tests/check_costs.pl, a tool to verify optimizer cost calculations.
- Most engine costs has been found with this program. All steps to
calculate the new costs are documented in Docs/optimizer_costs.txt
- User optimizer_cost variables are given in microseconds (as individual
costs can be very small). Internally they are stored in ms.
- Changed DISK_READ_COST (was DISK_SEEK_BASE_COST) from a hard disk cost
(9 ms) to common SSD cost (400MB/sec).
- Removed cost calculations for hard disks (rotation etc).
- Changed the following handler functions to return IO_AND_CPU_COST.
This makes it easy to apply different cost modifiers in ha_..time()
functions for io and cpu costs.
- scan_time()
- rnd_pos_time() & rnd_pos_call_time()
- keyread_time()
- Enhanched keyread_time() to calculate the full cost of reading of a set
of keys with a given number of ranges and optional number of blocks that
need to be accessed.
- Removed read_time() as keyread_time() + rnd_pos_time() can do the same
thing and more.
- Tuned cost for: heap, myisam, Aria, InnoDB, archive and MyRocks.
Used heap table costs for json_table. The rest are using default engine
costs.
- Added the following new optimizer variables:
- optimizer_disk_read_ratio
- optimizer_disk_read_cost
- optimizer_key_lookup_cost
- optimizer_row_lookup_cost
- optimizer_row_next_find_cost
- optimizer_scan_cost
- Moved all engine specific cost to OPTIMIZER_COSTS structure.
- Changed costs to use 'records_out' instead of 'records_read' when
recalculating costs.
- Split optimizer_costs.h to optimizer_costs.h and optimizer_defaults.h.
This allows one to change costs without having to compile a lot of
files.
- Updated costs for filter lookup.
- Use a better cost estimate in best_extension_by_limited_search()
for the sorting cost.
- Fixed previous issues with 'filtered' explain column as we are now
using 'records_out' (min rows seen for table) to calculate filtering.
This greatly simplifies the filtering code in
JOIN_TAB::save_explain_data().
This change caused a lot of queries to be optimized differently than
before, which exposed different issues in the optimizer that needs to
be fixed. These fixes are in the following commits. To not have to
change the same test case over and over again, the changes in the test
cases are done in a single commit after all the critical change sets
are done.
InnoDB changes:
- Updated InnoDB to not divide big range cost with 2.
- Added cost for InnoDB (innobase_update_optimizer_costs()).
- Don't mark clustered primary key with HA_KEYREAD_ONLY. This will
prevent that the optimizer is trying to use index-only scans on
the clustered key.
- Disabled ha_innobase::scan_time() and ha_innobase::read_time() and
ha_innobase::rnd_pos_time() as the default engine cost functions now
works good for InnoDB.
Other things:
- Added --show-query-costs (\Q) option to mysql.cc to show the query
cost after each query (good when working with query costs).
- Extended my_getopt with GET_ADJUSTED_VALUE which allows one to adjust
the value that user is given. This is used to change cost from
microseconds (user input) to milliseconds (what the server is
internally using).
- Added include/my_tracker.h ; Useful include file to quickly test
costs of a function.
- Use handler::set_table() in all places instead of 'table= arg'.
- Added SHOW_OPTIMIZER_COSTS to sys variables. These are input and
shown in microseconds for the user but stored as milliseconds.
This is to make the numbers easier to read for the user (less
pre-zeros). Implemented in 'Sys_var_optimizer_cost' class.
- In test_quick_select() do not use index scans if 'no_keyread' is set
for the table. This is what we do in other places of the server.
- Added THD parameter to Unique::get_use_cost() and
check_index_intersect_extension() and similar functions to be able
to provide costs to called functions.
- Changed 'records' to 'rows' in optimizer_trace.
- Write more information to optimizer_trace.
- Added INDEX_BLOCK_FILL_FACTOR_MUL (4) and INDEX_BLOCK_FILL_FACTOR_DIV (3)
to calculate usage space of keys in b-trees. (Before we used numeric
constants).
- Removed code that assumed that b-trees has similar costs as binary
trees. Replaced with engine calls that returns the cost.
- Added Bitmap::find_first_bit()
- Added timings to join_cache for ANALYZE table (patch by Sergei Petrunia).
- Added records_init and records_after_filter to POSITION to remember
more of what best_access_patch() calculates.
- table_after_join_selectivity() changed to recalculate 'records_out'
based on the new fields from best_access_patch()
Bug fixes:
- Some queries did not update last_query_cost (was 0). Fixed by moving
setting thd->...last_query_cost in JOIN::optimize().
- Write '0' as number of rows for const tables with a matching row.
Some internals:
- Engine cost are stored in OPTIMIZER_COSTS structure. When a
handlerton is created, we also created a new cost variable for the
handlerton. We also create a new variable if the user changes a
optimizer cost for a not yet loaded handlerton either with command
line arguments or with SET
@@global.engine.optimizer_cost_variable=xx.
- There are 3 global OPTIMIZER_COSTS variables:
default_optimizer_costs The default costs + changes from the
command line without an engine specifier.
heap_optimizer_costs Heap table costs, used for temporary tables
tmp_table_optimizer_costs The cost for the default on disk internal
temporary table (MyISAM or Aria)
- The engine cost for a table is stored in table_share. To speed up
accesses the handler has a pointer to this. The cost is copied
to the table on first access. If one wants to change the cost one
must first update the global engine cost and then do a FLUSH TABLES.
This was done to be able to access the costs for an open table
without any locks.
- When a handlerton is created, the cost are updated the following way:
See sql/keycaches.cc for details:
- Use 'default_optimizer_costs' as a base
- Call hton->update_optimizer_costs() to override with the engines
default costs.
- Override the costs that the user has specified for the engine.
- One handler open, copy the engine cost from handlerton to TABLE_SHARE.
- Call handler::update_optimizer_costs() to allow the engine to update
cost for this particular table.
- There are two costs stored in THD. These are copied to the handler
when the table is used in a query:
- optimizer_where_cost
- optimizer_scan_setup_cost
- Simply code in best_access_path() by storing all cost result in a
structure. (Idea/Suggestion by Igor)
2022-08-11 12:05:23 +02:00
|
|
|
federatedx_hton->update_optimizer_costs= federatedx_update_optimizer_costs;
|
2022-08-20 17:23:45 +02:00
|
|
|
federatedx_hton->create_unit= create_federatedx_unit_handler;
|
2009-10-30 19:50:56 +01:00
|
|
|
|
2011-07-13 21:10:18 +02:00
|
|
|
if (mysql_mutex_init(fe_key_mutex_federatedx,
|
|
|
|
&federatedx_mutex, MY_MUTEX_INIT_FAST))
|
2009-10-30 19:50:56 +01:00
|
|
|
goto error;
|
2024-10-26 19:34:26 +02:00
|
|
|
if (!my_hash_init(PSI_INSTRUMENT_ME, &federatedx_open_tables,
|
|
|
|
&my_charset_bin, 32, 0, 0, federatedx_share_get_key, 0,
|
|
|
|
0) &&
|
|
|
|
!my_hash_init(PSI_INSTRUMENT_ME, &federatedx_open_servers,
|
|
|
|
&my_charset_bin, 32, 0, 0, federatedx_server_get_key, 0,
|
|
|
|
0))
|
2009-10-30 19:50:56 +01:00
|
|
|
{
|
|
|
|
DBUG_RETURN(FALSE);
|
|
|
|
}
|
|
|
|
|
2011-07-13 21:10:18 +02:00
|
|
|
mysql_mutex_destroy(&federatedx_mutex);
|
2009-10-30 19:50:56 +01:00
|
|
|
error:
|
|
|
|
DBUG_RETURN(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Release the federatedx handler.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
federatedx_db_end()
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
FALSE OK
|
|
|
|
*/
|
|
|
|
|
|
|
|
int federatedx_done(void *p)
|
|
|
|
{
|
2011-04-25 17:22:25 +02:00
|
|
|
my_hash_free(&federatedx_open_tables);
|
|
|
|
my_hash_free(&federatedx_open_servers);
|
2011-07-13 21:10:18 +02:00
|
|
|
mysql_mutex_destroy(&federatedx_mutex);
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@brief Append identifiers to the string.
|
|
|
|
|
|
|
|
@param[in,out] string The target string.
|
|
|
|
@param[in] name Identifier name
|
|
|
|
@param[in] length Length of identifier name in bytes
|
|
|
|
@param[in] quote_char Quote char to use for quoting identifier.
|
|
|
|
|
|
|
|
@return Operation Status
|
|
|
|
@retval FALSE OK
|
|
|
|
@retval TRUE There was an error appending to the string.
|
|
|
|
|
|
|
|
@note This function is based upon the append_identifier() function
|
|
|
|
in sql_show.cc except that quoting always occurs.
|
|
|
|
*/
|
|
|
|
|
2018-02-06 13:55:58 +01:00
|
|
|
bool append_ident(String *string, const char *name, size_t length,
|
2009-10-30 19:50:56 +01:00
|
|
|
const char quote_char)
|
|
|
|
{
|
|
|
|
bool result;
|
|
|
|
uint clen;
|
|
|
|
const char *name_end;
|
|
|
|
DBUG_ENTER("append_ident");
|
|
|
|
|
|
|
|
if (quote_char)
|
|
|
|
{
|
|
|
|
string->reserve(length * 2 + 2);
|
|
|
|
if ((result= string->append("e_char, 1, system_charset_info)))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
for (name_end= name+length; name < name_end; name+= clen)
|
|
|
|
{
|
|
|
|
uchar c= *(uchar *) name;
|
2020-01-26 17:27:13 +01:00
|
|
|
clen= system_charset_info->charlen_fix(name, name_end);
|
2009-10-30 19:50:56 +01:00
|
|
|
if (clen == 1 && c == (uchar) quote_char &&
|
|
|
|
(result= string->append("e_char, 1, system_charset_info)))
|
|
|
|
goto err;
|
|
|
|
if ((result= string->append(name, clen, string->charset())))
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
result= string->append("e_char, 1, system_charset_info);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
result= string->append(name, length, system_charset_info);
|
|
|
|
|
|
|
|
err:
|
|
|
|
DBUG_RETURN(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-09 16:19:18 +02:00
|
|
|
static int parse_url_error(FEDERATEDX_SHARE *share, TABLE_SHARE *table_s,
|
|
|
|
int error_num)
|
2009-10-30 19:50:56 +01:00
|
|
|
{
|
|
|
|
char buf[FEDERATEDX_QUERY_BUFFER_SIZE];
|
2018-02-06 13:55:58 +01:00
|
|
|
size_t buf_len;
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_ENTER("ha_federatedx parse_url_error");
|
|
|
|
|
2013-07-21 16:39:19 +02:00
|
|
|
buf_len= MY_MIN(table_s->connect_string.length,
|
|
|
|
FEDERATEDX_QUERY_BUFFER_SIZE-1);
|
2013-04-09 16:19:18 +02:00
|
|
|
strmake(buf, table_s->connect_string.str, buf_len);
|
2013-05-20 23:58:44 +02:00
|
|
|
my_error(error_num, MYF(0), buf, 14);
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_RETURN(error_num);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
retrieve server object which contains server meta-data
|
|
|
|
from the system table given a server's name, set share
|
|
|
|
connection parameter members
|
|
|
|
*/
|
|
|
|
int get_connection(MEM_ROOT *mem_root, FEDERATEDX_SHARE *share)
|
|
|
|
{
|
|
|
|
int error_num= ER_FOREIGN_SERVER_DOESNT_EXIST;
|
|
|
|
FOREIGN_SERVER *server, server_buffer;
|
|
|
|
DBUG_ENTER("ha_federatedx::get_connection");
|
|
|
|
|
|
|
|
/*
|
|
|
|
get_server_by_name() clones the server if exists and allocates
|
|
|
|
copies of strings in the supplied mem_root
|
|
|
|
*/
|
|
|
|
if (!(server=
|
|
|
|
get_server_by_name(mem_root, share->connection_string, &server_buffer)))
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("get_server_by_name returned > 0 error condition!"));
|
|
|
|
/* need to come up with error handling */
|
|
|
|
error_num=1;
|
|
|
|
goto error;
|
|
|
|
}
|
2017-09-19 19:45:17 +02:00
|
|
|
DBUG_PRINT("info", ("get_server_by_name returned server at %p",
|
|
|
|
server));
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Most of these should never be empty strings, error handling will
|
|
|
|
need to be implemented. Also, is this the best way to set the share
|
|
|
|
members? Is there some allocation needed? In running this code, it works
|
|
|
|
except there are errors in the trace file of the share being overrun
|
|
|
|
at the address of the share.
|
|
|
|
*/
|
|
|
|
share->server_name_length= server->server_name_length;
|
2014-11-16 13:12:58 +01:00
|
|
|
share->server_name= const_cast<char*>(server->server_name);
|
|
|
|
share->username= const_cast<char*>(server->username);
|
|
|
|
share->password= const_cast<char*>(server->password);
|
|
|
|
share->database= const_cast<char*>(server->db);
|
2011-07-02 22:12:12 +02:00
|
|
|
share->port= server->port > MIN_PORT && server->port < 65536 ?
|
2009-10-30 19:50:56 +01:00
|
|
|
(ushort) server->port : MYSQL_PORT;
|
2014-11-16 13:12:58 +01:00
|
|
|
share->hostname= const_cast<char*>(server->host);
|
|
|
|
if (!(share->socket= const_cast<char*>(server->socket)) &&
|
2009-10-30 19:50:56 +01:00
|
|
|
!strcmp(share->hostname, my_localhost))
|
|
|
|
share->socket= (char *) MYSQL_UNIX_ADDR;
|
2014-11-16 13:12:58 +01:00
|
|
|
share->scheme= const_cast<char*>(server->scheme);
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
DBUG_PRINT("info", ("share->username: %s", share->username));
|
|
|
|
DBUG_PRINT("info", ("share->password: %s", share->password));
|
|
|
|
DBUG_PRINT("info", ("share->hostname: %s", share->hostname));
|
|
|
|
DBUG_PRINT("info", ("share->database: %s", share->database));
|
|
|
|
DBUG_PRINT("info", ("share->port: %d", share->port));
|
|
|
|
DBUG_PRINT("info", ("share->socket: %s", share->socket));
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
|
|
|
|
error:
|
2013-05-21 13:03:37 +02:00
|
|
|
my_printf_error(error_num, "server name: '%s' doesn't exist!",
|
|
|
|
MYF(0), share->connection_string);
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_RETURN(error_num);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Parse connection info from table->s->connect_string
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
parse_url()
|
|
|
|
mem_root MEM_ROOT pointer for memory allocation
|
|
|
|
share pointer to FEDERATEDX share
|
2022-10-25 14:30:42 +02:00
|
|
|
table_s pointer to current TABLE_SHARE class
|
2009-10-30 19:50:56 +01:00
|
|
|
table_create_flag determines what error to throw
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
Populates the share with information about the connection
|
|
|
|
to the foreign database that will serve as the data source.
|
|
|
|
This string must be specified (currently) in the "CONNECTION" field,
|
|
|
|
listed in the CREATE TABLE statement.
|
|
|
|
|
|
|
|
This string MUST be in the format of any of these:
|
|
|
|
|
|
|
|
CONNECTION="scheme://username:password@hostname:port/database/table"
|
|
|
|
CONNECTION="scheme://username@hostname/database/table"
|
|
|
|
CONNECTION="scheme://username@hostname:port/database/table"
|
|
|
|
CONNECTION="scheme://username:password@hostname/database/table"
|
|
|
|
|
|
|
|
_OR_
|
|
|
|
|
|
|
|
CONNECTION="connection name"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
An Example:
|
|
|
|
|
|
|
|
CREATE TABLE t1 (id int(32))
|
|
|
|
ENGINE="FEDERATEDX"
|
|
|
|
CONNECTION="mysql://joe:joespass@192.168.1.111:9308/federatedx/testtable";
|
|
|
|
|
|
|
|
CREATE TABLE t2 (
|
|
|
|
id int(4) NOT NULL auto_increment,
|
|
|
|
name varchar(32) NOT NULL,
|
|
|
|
PRIMARY KEY(id)
|
|
|
|
) ENGINE="FEDERATEDX" CONNECTION="my_conn";
|
|
|
|
|
|
|
|
***IMPORTANT***
|
|
|
|
Currently, the FederatedX Storage Engine only supports connecting to another
|
|
|
|
Database ("scheme" of "mysql"). Connections using JDBC as well as
|
|
|
|
other connectors are in the planning stage.
|
|
|
|
|
|
|
|
|
|
|
|
'password' and 'port' are both optional.
|
|
|
|
|
|
|
|
RETURN VALUE
|
|
|
|
0 success
|
|
|
|
error_num particular error code
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2013-04-09 16:19:18 +02:00
|
|
|
static int parse_url(MEM_ROOT *mem_root, FEDERATEDX_SHARE *share,
|
|
|
|
TABLE_SHARE *table_s, uint table_create_flag)
|
2009-10-30 19:50:56 +01:00
|
|
|
{
|
|
|
|
uint error_num= (table_create_flag ?
|
|
|
|
ER_FOREIGN_DATA_STRING_INVALID_CANT_CREATE :
|
|
|
|
ER_FOREIGN_DATA_STRING_INVALID);
|
|
|
|
DBUG_ENTER("ha_federatedx::parse_url");
|
|
|
|
|
|
|
|
share->port= 0;
|
|
|
|
share->socket= 0;
|
2017-09-19 19:45:17 +02:00
|
|
|
DBUG_PRINT("info", ("share at %p", share));
|
2013-04-09 16:19:18 +02:00
|
|
|
DBUG_PRINT("info", ("Length: %u", (uint) table_s->connect_string.length));
|
|
|
|
DBUG_PRINT("info", ("String: '%.*s'", (int) table_s->connect_string.length,
|
|
|
|
table_s->connect_string.str));
|
|
|
|
share->connection_string= strmake_root(mem_root, table_s->connect_string.str,
|
|
|
|
table_s->connect_string.length);
|
2009-10-30 19:50:56 +01:00
|
|
|
|
2017-09-19 19:45:17 +02:00
|
|
|
DBUG_PRINT("info",("parse_url alloced share->connection_string %p",
|
|
|
|
share->connection_string));
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
DBUG_PRINT("info",("share->connection_string: %s",share->connection_string));
|
|
|
|
/*
|
|
|
|
No :// or @ in connection string. Must be a straight connection name of
|
|
|
|
either "servername" or "servername/tablename"
|
|
|
|
*/
|
|
|
|
if ((!strstr(share->connection_string, "://") &&
|
|
|
|
(!strchr(share->connection_string, '@'))))
|
|
|
|
{
|
|
|
|
|
|
|
|
DBUG_PRINT("info",
|
|
|
|
("share->connection_string: %s internal format "
|
2017-09-19 19:45:17 +02:00
|
|
|
"share->connection_string: %p",
|
2009-10-30 19:50:56 +01:00
|
|
|
share->connection_string,
|
2017-09-19 19:45:17 +02:00
|
|
|
share->connection_string));
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
/* ok, so we do a little parsing, but not completely! */
|
|
|
|
share->parsed= FALSE;
|
|
|
|
/*
|
|
|
|
If there is a single '/' in the connection string, this means the user is
|
|
|
|
specifying a table name
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((share->table_name= strchr(share->connection_string, '/')))
|
|
|
|
{
|
|
|
|
*share->table_name++= '\0';
|
|
|
|
share->table_name_length= strlen(share->table_name);
|
|
|
|
|
|
|
|
DBUG_PRINT("info",
|
|
|
|
("internal format, parsed table_name "
|
|
|
|
"share->connection_string: %s share->table_name: %s",
|
|
|
|
share->connection_string, share->table_name));
|
|
|
|
|
|
|
|
/*
|
|
|
|
there better not be any more '/'s !
|
|
|
|
*/
|
|
|
|
if (strchr(share->table_name, '/'))
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
Otherwise, straight server name, use tablename of federatedx table
|
|
|
|
as remote table name
|
|
|
|
*/
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Connection specifies everything but, resort to
|
|
|
|
expecting remote and foreign table names to match
|
|
|
|
*/
|
2013-04-09 16:19:18 +02:00
|
|
|
share->table_name= strmake_root(mem_root, table_s->table_name.str,
|
2009-10-30 19:50:56 +01:00
|
|
|
(share->table_name_length=
|
2013-04-09 16:19:18 +02:00
|
|
|
table_s->table_name.length));
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_PRINT("info",
|
|
|
|
("internal format, default table_name "
|
|
|
|
"share->connection_string: %s share->table_name: %s",
|
|
|
|
share->connection_string, share->table_name));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((error_num= get_connection(mem_root, share)))
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
share->parsed= TRUE;
|
|
|
|
// Add a null for later termination of table name
|
2013-04-09 16:19:18 +02:00
|
|
|
share->connection_string[table_s->connect_string.length]= 0;
|
2009-10-30 19:50:56 +01:00
|
|
|
share->scheme= share->connection_string;
|
2017-09-19 19:45:17 +02:00
|
|
|
DBUG_PRINT("info",("parse_url alloced share->scheme: %p",
|
|
|
|
share->scheme));
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Remove addition of null terminator and store length
|
|
|
|
for each string in share
|
|
|
|
*/
|
|
|
|
if (!(share->username= strstr(share->scheme, "://")))
|
|
|
|
goto error;
|
|
|
|
share->scheme[share->username - share->scheme]= '\0';
|
|
|
|
|
|
|
|
if (!federatedx_io::handles_scheme(share->scheme))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
share->username+= 3;
|
|
|
|
|
|
|
|
if (!(share->hostname= strchr(share->username, '@')))
|
|
|
|
goto error;
|
|
|
|
*share->hostname++= '\0'; // End username
|
|
|
|
|
|
|
|
if ((share->password= strchr(share->username, ':')))
|
|
|
|
{
|
|
|
|
*share->password++= '\0'; // End username
|
|
|
|
|
|
|
|
/* make sure there isn't an extra / or @ */
|
|
|
|
if ((strchr(share->password, '/') || strchr(share->hostname, '@')))
|
|
|
|
goto error;
|
|
|
|
/*
|
|
|
|
Found that if the string is:
|
|
|
|
user:@hostname:port/db/table
|
|
|
|
Then password is a null string, so set to NULL
|
|
|
|
*/
|
2013-03-28 20:04:14 +01:00
|
|
|
if (share->password[0] == '\0')
|
2009-10-30 19:50:56 +01:00
|
|
|
share->password= NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make sure there isn't an extra / or @ */
|
|
|
|
if ((strchr(share->username, '/')) || (strchr(share->hostname, '@')))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!(share->database= strchr(share->hostname, '/')))
|
|
|
|
goto error;
|
|
|
|
*share->database++= '\0';
|
|
|
|
|
|
|
|
if ((share->sport= strchr(share->hostname, ':')))
|
|
|
|
{
|
|
|
|
*share->sport++= '\0';
|
|
|
|
if (share->sport[0] == '\0')
|
|
|
|
share->sport= NULL;
|
|
|
|
else
|
|
|
|
share->port= atoi(share->sport);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(share->table_name= strchr(share->database, '/')))
|
|
|
|
goto error;
|
|
|
|
*share->table_name++= '\0';
|
|
|
|
|
|
|
|
share->table_name_length= strlen(share->table_name);
|
|
|
|
|
|
|
|
/* make sure there's not an extra / */
|
|
|
|
if ((strchr(share->table_name, '/')))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (share->hostname[0] == '\0')
|
2019-11-22 12:30:13 +01:00
|
|
|
share->hostname= strdup_root(mem_root, my_localhost);
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
if (!share->port)
|
|
|
|
{
|
2019-11-22 12:30:13 +01:00
|
|
|
if (0 == strcmp(share->hostname, my_localhost))
|
2009-10-30 19:50:56 +01:00
|
|
|
share->socket= (char *) MYSQL_UNIX_ADDR;
|
|
|
|
else
|
|
|
|
share->port= MYSQL_PORT;
|
|
|
|
}
|
|
|
|
|
|
|
|
DBUG_PRINT("info",
|
|
|
|
("scheme: %s username: %s password: %s hostname: %s "
|
|
|
|
"port: %d db: %s tablename: %s",
|
|
|
|
share->scheme, share->username, share->password,
|
|
|
|
share->hostname, share->port, share->database,
|
|
|
|
share->table_name));
|
|
|
|
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
|
|
|
|
error:
|
2013-04-09 16:19:18 +02:00
|
|
|
DBUG_RETURN(parse_url_error(share, table_s, error_num));
|
2009-10-30 19:50:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
** FEDERATEDX tables
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
ha_federatedx::ha_federatedx(handlerton *hton,
|
|
|
|
TABLE_SHARE *table_arg)
|
|
|
|
:handler(hton, table_arg),
|
|
|
|
txn(0), io(0), stored_result(0)
|
|
|
|
{
|
|
|
|
bzero(&bulk_insert, sizeof(bulk_insert));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Convert MySQL result set row to handler internal format
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
convert_row_to_internal_format()
|
|
|
|
record Byte pointer to record
|
|
|
|
row MySQL result set row from fetchrow()
|
|
|
|
result Result set to use
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
This method simply iterates through a row returned via fetchrow with
|
|
|
|
values from a successful SELECT , and then stores each column's value
|
|
|
|
in the field object via the field object pointer (pointing to the table's
|
|
|
|
array of field object pointers). This is how the handler needs the data
|
|
|
|
to be stored to then return results back to the user
|
|
|
|
|
|
|
|
RETURN VALUE
|
|
|
|
0 After fields have had field values stored from record
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint ha_federatedx::convert_row_to_internal_format(uchar *record,
|
|
|
|
FEDERATEDX_IO_ROW *row,
|
|
|
|
FEDERATEDX_IO_RESULT *result)
|
|
|
|
{
|
|
|
|
ulong *lengths;
|
|
|
|
Field **field;
|
|
|
|
int column= 0;
|
MDEV-17556 Assertion `bitmap_is_set_all(&table->s->all_set)' failed
The assertion failed in handler::ha_reset upon SELECT under
READ UNCOMMITTED from table with index on virtual column.
This was the debug-only failure, though the problem is mush wider:
* MY_BITMAP is a structure containing my_bitmap_map, the latter is a raw
bitmap.
* read_set, write_set and vcol_set of TABLE are the pointers to MY_BITMAP
* The rest of MY_BITMAPs are stored in TABLE and TABLE_SHARE
* The pointers to the stored MY_BITMAPs, like orig_read_set etc, and
sometimes all_set and tmp_set, are assigned to the pointers.
* Sometimes tmp_use_all_columns is used to substitute the raw bitmap
directly with all_set.bitmap
* Sometimes even bitmaps are directly modified, like in
TABLE::update_virtual_field(): bitmap_clear_all(&tmp_set) is called.
The last three bullets in the list, when used together (which is mostly
always) make the program flow cumbersome and impossible to follow,
notwithstanding the errors they cause, like this MDEV-17556, where tmp_set
pointer was assigned to read_set, write_set and vcol_set, then its bitmap
was substituted with all_set.bitmap by dbug_tmp_use_all_columns() call,
and then bitmap_clear_all(&tmp_set) was applied to all this.
To untangle this knot, the rule should be applied:
* Never substitute bitmaps! This patch is about this.
orig_*, all_set bitmaps are never substituted already.
This patch changes the following function prototypes:
* tmp_use_all_columns, dbug_tmp_use_all_columns
to accept MY_BITMAP** and to return MY_BITMAP * instead of my_bitmap_map*
* tmp_restore_column_map, dbug_tmp_restore_column_maps to accept
MY_BITMAP* instead of my_bitmap_map*
These functions now will substitute read_set/write_set/vcol_set directly,
and won't touch underlying bitmaps.
2020-12-29 04:38:16 +01:00
|
|
|
MY_BITMAP *old_map= dbug_tmp_use_all_columns(table, &table->write_set);
|
2018-05-14 10:47:13 +02:00
|
|
|
Time_zone *saved_time_zone= table->in_use->variables.time_zone;
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_ENTER("ha_federatedx::convert_row_to_internal_format");
|
|
|
|
|
2018-05-14 10:47:13 +02:00
|
|
|
table->in_use->variables.time_zone= UTC;
|
2009-10-30 19:50:56 +01:00
|
|
|
lengths= io->fetch_lengths(result);
|
|
|
|
|
|
|
|
for (field= table->field; *field; field++, column++)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
index variable to move us through the row at the
|
|
|
|
same iterative step as the field
|
|
|
|
*/
|
|
|
|
my_ptrdiff_t old_ptr;
|
|
|
|
old_ptr= (my_ptrdiff_t) (record - table->record[0]);
|
|
|
|
(*field)->move_field_offset(old_ptr);
|
|
|
|
if (io->is_column_null(row, column))
|
|
|
|
(*field)->set_null();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (bitmap_is_set(table->read_set, (*field)->field_index))
|
|
|
|
{
|
|
|
|
(*field)->set_notnull();
|
2019-10-11 21:16:01 +02:00
|
|
|
(*field)->store_text(io->get_column_data(row, column), lengths[column],
|
|
|
|
&my_charset_bin);
|
2009-10-30 19:50:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
(*field)->move_field_offset(-old_ptr);
|
|
|
|
}
|
2018-05-14 10:47:13 +02:00
|
|
|
table->in_use->variables.time_zone= saved_time_zone;
|
MDEV-17556 Assertion `bitmap_is_set_all(&table->s->all_set)' failed
The assertion failed in handler::ha_reset upon SELECT under
READ UNCOMMITTED from table with index on virtual column.
This was the debug-only failure, though the problem is mush wider:
* MY_BITMAP is a structure containing my_bitmap_map, the latter is a raw
bitmap.
* read_set, write_set and vcol_set of TABLE are the pointers to MY_BITMAP
* The rest of MY_BITMAPs are stored in TABLE and TABLE_SHARE
* The pointers to the stored MY_BITMAPs, like orig_read_set etc, and
sometimes all_set and tmp_set, are assigned to the pointers.
* Sometimes tmp_use_all_columns is used to substitute the raw bitmap
directly with all_set.bitmap
* Sometimes even bitmaps are directly modified, like in
TABLE::update_virtual_field(): bitmap_clear_all(&tmp_set) is called.
The last three bullets in the list, when used together (which is mostly
always) make the program flow cumbersome and impossible to follow,
notwithstanding the errors they cause, like this MDEV-17556, where tmp_set
pointer was assigned to read_set, write_set and vcol_set, then its bitmap
was substituted with all_set.bitmap by dbug_tmp_use_all_columns() call,
and then bitmap_clear_all(&tmp_set) was applied to all this.
To untangle this knot, the rule should be applied:
* Never substitute bitmaps! This patch is about this.
orig_*, all_set bitmaps are never substituted already.
This patch changes the following function prototypes:
* tmp_use_all_columns, dbug_tmp_use_all_columns
to accept MY_BITMAP** and to return MY_BITMAP * instead of my_bitmap_map*
* tmp_restore_column_map, dbug_tmp_restore_column_maps to accept
MY_BITMAP* instead of my_bitmap_map*
These functions now will substitute read_set/write_set/vcol_set directly,
and won't touch underlying bitmaps.
2020-12-29 04:38:16 +01:00
|
|
|
dbug_tmp_restore_column_map(&table->write_set, old_map);
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool emit_key_part_name(String *to, KEY_PART_INFO *part)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("emit_key_part_name");
|
2017-04-23 18:39:57 +02:00
|
|
|
if (append_ident(to, part->field->field_name.str,
|
|
|
|
part->field->field_name.length, ident_quote_char))
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_RETURN(1); // Out of memory
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool emit_key_part_element(String *to, KEY_PART_INFO *part,
|
|
|
|
bool needs_quotes, bool is_like,
|
|
|
|
const uchar *ptr, uint len)
|
|
|
|
{
|
|
|
|
Field *field= part->field;
|
|
|
|
DBUG_ENTER("emit_key_part_element");
|
|
|
|
|
|
|
|
if (needs_quotes && to->append(STRING_WITH_LEN("'")))
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
|
|
|
|
if (part->type == HA_KEYTYPE_BIT)
|
|
|
|
{
|
|
|
|
char buff[STRING_BUFFER_USUAL_SIZE], *buf= buff;
|
|
|
|
|
|
|
|
*buf++= '0';
|
|
|
|
*buf++= 'x';
|
2023-09-27 16:03:11 +02:00
|
|
|
buf= octet2hex(buf, ptr, len);
|
2009-10-30 19:50:56 +01:00
|
|
|
if (to->append((char*) buff, (uint)(buf - buff)))
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
else if (part->key_part_flag & HA_BLOB_PART)
|
|
|
|
{
|
|
|
|
uint blob_length= uint2korr(ptr);
|
Reduce usage of strlen()
Changes:
- To detect automatic strlen() I removed the methods in String that
uses 'const char *' without a length:
- String::append(const char*)
- Binary_string(const char *str)
- String(const char *str, CHARSET_INFO *cs)
- append_for_single_quote(const char *)
All usage of append(const char*) is changed to either use
String::append(char), String::append(const char*, size_t length) or
String::append(LEX_CSTRING)
- Added STRING_WITH_LEN() around constant string arguments to
String::append()
- Added overflow argument to escape_string_for_mysql() and
escape_quotes_for_mysql() instead of returning (size_t) -1 on overflow.
This was needed as most usage of the above functions never tested the
result for -1 and would have given wrong results or crashes in case
of overflows.
- Added Item_func_or_sum::func_name_cstring(), which returns LEX_CSTRING.
Changed all Item_func::func_name()'s to func_name_cstring()'s.
The old Item_func_or_sum::func_name() is now an inline function that
returns func_name_cstring().str.
- Changed Item::mode_name() and Item::func_name_ext() to return
LEX_CSTRING.
- Changed for some functions the name argument from const char * to
to const LEX_CSTRING &:
- Item::Item_func_fix_attributes()
- Item::check_type_...()
- Type_std_attributes::agg_item_collations()
- Type_std_attributes::agg_item_set_converter()
- Type_std_attributes::agg_arg_charsets...()
- Type_handler_hybrid_field_type::aggregate_for_result()
- Type_handler_geometry::check_type_geom_or_binary()
- Type_handler::Item_func_or_sum_illegal_param()
- Predicant_to_list_comparator::add_value_skip_null()
- Predicant_to_list_comparator::add_value()
- cmp_item_row::prepare_comparators()
- cmp_item_row::aggregate_row_elements_for_comparison()
- Cursor_ref::print_func()
- Removes String_space() as it was only used in one cases and that
could be simplified to not use String_space(), thanks to the fixed
my_vsnprintf().
- Added some const LEX_CSTRING's for common strings:
- NULL_clex_str, DATA_clex_str, INDEX_clex_str.
- Changed primary_key_name to a LEX_CSTRING
- Renamed String::set_quick() to String::set_buffer_if_not_allocated() to
clarify what the function really does.
- Rename of protocol function:
bool store(const char *from, CHARSET_INFO *cs) to
bool store_string_or_null(const char *from, CHARSET_INFO *cs).
This was done to both clarify the difference between this 'store' function
and also to make it easier to find unoptimal usage of store() calls.
- Added Protocol::store(const LEX_CSTRING*, CHARSET_INFO*)
- Changed some 'const char*' arrays to instead be of type LEX_CSTRING.
- class Item_func_units now used LEX_CSTRING for name.
Other things:
- Fixed a bug in mysql.cc:construct_prompt() where a wrong escape character
in the prompt would cause some part of the prompt to be duplicated.
- Fixed a lot of instances where the length of the argument to
append is known or easily obtain but was not used.
- Removed some not needed 'virtual' definition for functions that was
inherited from the parent. I added override to these.
- Fixed Ordered_key::print() to preallocate needed buffer. Old code could
case memory overruns.
- Simplified some loops when adding char * to a String with delimiters.
2020-08-12 19:29:55 +02:00
|
|
|
String blob((char*) ptr+HA_KEY_BLOB_LENGTH,
|
|
|
|
blob_length, &my_charset_bin);
|
2014-03-26 09:41:52 +01:00
|
|
|
if (to->append_for_single_quote(&blob))
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
else if (part->key_part_flag & HA_VAR_LENGTH_PART)
|
|
|
|
{
|
|
|
|
uint var_length= uint2korr(ptr);
|
Reduce usage of strlen()
Changes:
- To detect automatic strlen() I removed the methods in String that
uses 'const char *' without a length:
- String::append(const char*)
- Binary_string(const char *str)
- String(const char *str, CHARSET_INFO *cs)
- append_for_single_quote(const char *)
All usage of append(const char*) is changed to either use
String::append(char), String::append(const char*, size_t length) or
String::append(LEX_CSTRING)
- Added STRING_WITH_LEN() around constant string arguments to
String::append()
- Added overflow argument to escape_string_for_mysql() and
escape_quotes_for_mysql() instead of returning (size_t) -1 on overflow.
This was needed as most usage of the above functions never tested the
result for -1 and would have given wrong results or crashes in case
of overflows.
- Added Item_func_or_sum::func_name_cstring(), which returns LEX_CSTRING.
Changed all Item_func::func_name()'s to func_name_cstring()'s.
The old Item_func_or_sum::func_name() is now an inline function that
returns func_name_cstring().str.
- Changed Item::mode_name() and Item::func_name_ext() to return
LEX_CSTRING.
- Changed for some functions the name argument from const char * to
to const LEX_CSTRING &:
- Item::Item_func_fix_attributes()
- Item::check_type_...()
- Type_std_attributes::agg_item_collations()
- Type_std_attributes::agg_item_set_converter()
- Type_std_attributes::agg_arg_charsets...()
- Type_handler_hybrid_field_type::aggregate_for_result()
- Type_handler_geometry::check_type_geom_or_binary()
- Type_handler::Item_func_or_sum_illegal_param()
- Predicant_to_list_comparator::add_value_skip_null()
- Predicant_to_list_comparator::add_value()
- cmp_item_row::prepare_comparators()
- cmp_item_row::aggregate_row_elements_for_comparison()
- Cursor_ref::print_func()
- Removes String_space() as it was only used in one cases and that
could be simplified to not use String_space(), thanks to the fixed
my_vsnprintf().
- Added some const LEX_CSTRING's for common strings:
- NULL_clex_str, DATA_clex_str, INDEX_clex_str.
- Changed primary_key_name to a LEX_CSTRING
- Renamed String::set_quick() to String::set_buffer_if_not_allocated() to
clarify what the function really does.
- Rename of protocol function:
bool store(const char *from, CHARSET_INFO *cs) to
bool store_string_or_null(const char *from, CHARSET_INFO *cs).
This was done to both clarify the difference between this 'store' function
and also to make it easier to find unoptimal usage of store() calls.
- Added Protocol::store(const LEX_CSTRING*, CHARSET_INFO*)
- Changed some 'const char*' arrays to instead be of type LEX_CSTRING.
- class Item_func_units now used LEX_CSTRING for name.
Other things:
- Fixed a bug in mysql.cc:construct_prompt() where a wrong escape character
in the prompt would cause some part of the prompt to be duplicated.
- Fixed a lot of instances where the length of the argument to
append is known or easily obtain but was not used.
- Removed some not needed 'virtual' definition for functions that was
inherited from the parent. I added override to these.
- Fixed Ordered_key::print() to preallocate needed buffer. Old code could
case memory overruns.
- Simplified some loops when adding char * to a String with delimiters.
2020-08-12 19:29:55 +02:00
|
|
|
String varchar((char*) ptr+HA_KEY_BLOB_LENGTH,
|
|
|
|
var_length, &my_charset_bin);
|
2014-03-26 09:41:52 +01:00
|
|
|
if (to->append_for_single_quote(&varchar))
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char strbuff[MAX_FIELD_WIDTH];
|
|
|
|
String str(strbuff, sizeof(strbuff), part->field->charset()), *res;
|
|
|
|
|
|
|
|
res= field->val_str(&str, ptr);
|
|
|
|
|
|
|
|
if (field->result_type() == STRING_RESULT)
|
|
|
|
{
|
2014-03-26 09:41:52 +01:00
|
|
|
if (to->append_for_single_quote(res))
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
else if (to->append(res->ptr(), res->length()))
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_like && to->append(STRING_WITH_LEN("%")))
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
|
|
|
|
if (needs_quotes && to->append(STRING_WITH_LEN("'")))
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Create a WHERE clause based off of values in keys
|
|
|
|
Note: This code was inspired by key_copy from key.cc
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
create_where_from_key ()
|
|
|
|
to String object to store WHERE clause
|
|
|
|
key_info KEY struct pointer
|
|
|
|
key byte pointer containing key
|
|
|
|
key_length length of key
|
|
|
|
range_type 0 - no range, 1 - min range, 2 - max range
|
|
|
|
(see enum range_operation)
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
Using iteration through all the keys via a KEY_PART_INFO pointer,
|
|
|
|
This method 'extracts' the value of each key in the byte pointer
|
|
|
|
*key, and for each key found, constructs an appropriate WHERE clause
|
|
|
|
|
|
|
|
RETURN VALUE
|
|
|
|
0 After all keys have been accounted for to create the WHERE clause
|
|
|
|
1 No keys found
|
|
|
|
|
|
|
|
Range flags Table per Timour:
|
|
|
|
|
|
|
|
-----------------
|
|
|
|
- start_key:
|
|
|
|
* ">" -> HA_READ_AFTER_KEY
|
|
|
|
* ">=" -> HA_READ_KEY_OR_NEXT
|
|
|
|
* "=" -> HA_READ_KEY_EXACT
|
|
|
|
|
|
|
|
- end_key:
|
|
|
|
* "<" -> HA_READ_BEFORE_KEY
|
|
|
|
* "<=" -> HA_READ_AFTER_KEY
|
|
|
|
|
|
|
|
records_in_range:
|
|
|
|
-----------------
|
|
|
|
- start_key:
|
|
|
|
* ">" -> HA_READ_AFTER_KEY
|
|
|
|
* ">=" -> HA_READ_KEY_EXACT
|
|
|
|
* "=" -> HA_READ_KEY_EXACT
|
|
|
|
|
|
|
|
- end_key:
|
|
|
|
* "<" -> HA_READ_BEFORE_KEY
|
|
|
|
* "<=" -> HA_READ_AFTER_KEY
|
|
|
|
* "=" -> HA_READ_AFTER_KEY
|
|
|
|
|
|
|
|
0 HA_READ_KEY_EXACT, Find first record else error
|
|
|
|
1 HA_READ_KEY_OR_NEXT, Record or next record
|
|
|
|
2 HA_READ_KEY_OR_PREV, Record or previous
|
|
|
|
3 HA_READ_AFTER_KEY, Find next rec. after key-record
|
|
|
|
4 HA_READ_BEFORE_KEY, Find next rec. before key-record
|
|
|
|
5 HA_READ_PREFIX, Key which as same prefix
|
|
|
|
6 HA_READ_PREFIX_LAST, Last key with the same prefix
|
|
|
|
7 HA_READ_PREFIX_LAST_OR_PREV, Last or prev key with the same prefix
|
|
|
|
|
|
|
|
Flags that I've found:
|
|
|
|
|
|
|
|
id, primary key, varchar
|
|
|
|
|
|
|
|
id = 'ccccc'
|
|
|
|
records_in_range: start_key 0 end_key 3
|
|
|
|
read_range_first: start_key 0 end_key NULL
|
|
|
|
|
|
|
|
id > 'ccccc'
|
|
|
|
records_in_range: start_key 3 end_key NULL
|
|
|
|
read_range_first: start_key 3 end_key NULL
|
|
|
|
|
|
|
|
id < 'ccccc'
|
|
|
|
records_in_range: start_key NULL end_key 4
|
|
|
|
read_range_first: start_key NULL end_key 4
|
|
|
|
|
|
|
|
id <= 'ccccc'
|
|
|
|
records_in_range: start_key NULL end_key 3
|
|
|
|
read_range_first: start_key NULL end_key 3
|
|
|
|
|
|
|
|
id >= 'ccccc'
|
|
|
|
records_in_range: start_key 0 end_key NULL
|
|
|
|
read_range_first: start_key 1 end_key NULL
|
|
|
|
|
|
|
|
id like 'cc%cc'
|
|
|
|
records_in_range: start_key 0 end_key 3
|
|
|
|
read_range_first: start_key 1 end_key 3
|
|
|
|
|
|
|
|
id > 'aaaaa' and id < 'ccccc'
|
|
|
|
records_in_range: start_key 3 end_key 4
|
|
|
|
read_range_first: start_key 3 end_key 4
|
|
|
|
|
|
|
|
id >= 'aaaaa' and id < 'ccccc';
|
|
|
|
records_in_range: start_key 0 end_key 4
|
|
|
|
read_range_first: start_key 1 end_key 4
|
|
|
|
|
|
|
|
id >= 'aaaaa' and id <= 'ccccc';
|
|
|
|
records_in_range: start_key 0 end_key 3
|
|
|
|
read_range_first: start_key 1 end_key 3
|
|
|
|
|
|
|
|
id > 'aaaaa' and id <= 'ccccc';
|
|
|
|
records_in_range: start_key 3 end_key 3
|
|
|
|
read_range_first: start_key 3 end_key 3
|
|
|
|
|
|
|
|
numeric keys:
|
|
|
|
|
|
|
|
id = 4
|
|
|
|
index_read_idx: start_key 0 end_key NULL
|
|
|
|
|
|
|
|
id > 4
|
|
|
|
records_in_range: start_key 3 end_key NULL
|
|
|
|
read_range_first: start_key 3 end_key NULL
|
|
|
|
|
|
|
|
id >= 4
|
|
|
|
records_in_range: start_key 0 end_key NULL
|
|
|
|
read_range_first: start_key 1 end_key NULL
|
|
|
|
|
|
|
|
id < 4
|
|
|
|
records_in_range: start_key NULL end_key 4
|
|
|
|
read_range_first: start_key NULL end_key 4
|
|
|
|
|
|
|
|
id <= 4
|
|
|
|
records_in_range: start_key NULL end_key 3
|
|
|
|
read_range_first: start_key NULL end_key 3
|
|
|
|
|
|
|
|
id like 4
|
|
|
|
full table scan, select * from
|
|
|
|
|
|
|
|
id > 2 and id < 8
|
|
|
|
records_in_range: start_key 3 end_key 4
|
|
|
|
read_range_first: start_key 3 end_key 4
|
|
|
|
|
|
|
|
id >= 2 and id < 8
|
|
|
|
records_in_range: start_key 0 end_key 4
|
|
|
|
read_range_first: start_key 1 end_key 4
|
|
|
|
|
|
|
|
id >= 2 and id <= 8
|
|
|
|
records_in_range: start_key 0 end_key 3
|
|
|
|
read_range_first: start_key 1 end_key 3
|
|
|
|
|
|
|
|
id > 2 and id <= 8
|
|
|
|
records_in_range: start_key 3 end_key 3
|
|
|
|
read_range_first: start_key 3 end_key 3
|
|
|
|
|
|
|
|
multi keys (id int, name varchar, other varchar)
|
|
|
|
|
|
|
|
id = 1;
|
|
|
|
records_in_range: start_key 0 end_key 3
|
|
|
|
read_range_first: start_key 0 end_key NULL
|
|
|
|
|
|
|
|
id > 4;
|
|
|
|
id > 2 and name = '333'; remote: id > 2
|
|
|
|
id > 2 and name > '333'; remote: id > 2
|
|
|
|
id > 2 and name > '333' and other < 'ddd'; remote: id > 2 no results
|
|
|
|
id > 2 and name >= '333' and other < 'ddd'; remote: id > 2 1 result
|
|
|
|
id >= 4 and name = 'eric was here' and other > 'eeee';
|
|
|
|
records_in_range: start_key 3 end_key NULL
|
|
|
|
read_range_first: start_key 3 end_key NULL
|
|
|
|
|
|
|
|
id >= 4;
|
|
|
|
id >= 2 and name = '333' and other < 'ddd';
|
|
|
|
remote: `id` >= 2 AND `name` >= '333';
|
|
|
|
records_in_range: start_key 0 end_key NULL
|
|
|
|
read_range_first: start_key 1 end_key NULL
|
|
|
|
|
|
|
|
id < 4;
|
|
|
|
id < 3 and name = '222' and other <= 'ccc'; remote: id < 3
|
|
|
|
records_in_range: start_key NULL end_key 4
|
|
|
|
read_range_first: start_key NULL end_key 4
|
|
|
|
|
|
|
|
id <= 4;
|
|
|
|
records_in_range: start_key NULL end_key 3
|
|
|
|
read_range_first: start_key NULL end_key 3
|
|
|
|
|
|
|
|
id like 4;
|
|
|
|
full table scan
|
|
|
|
|
|
|
|
id > 2 and id < 4;
|
|
|
|
records_in_range: start_key 3 end_key 4
|
|
|
|
read_range_first: start_key 3 end_key 4
|
|
|
|
|
|
|
|
id >= 2 and id < 4;
|
|
|
|
records_in_range: start_key 0 end_key 4
|
|
|
|
read_range_first: start_key 1 end_key 4
|
|
|
|
|
|
|
|
id >= 2 and id <= 4;
|
|
|
|
records_in_range: start_key 0 end_key 3
|
|
|
|
read_range_first: start_key 1 end_key 3
|
|
|
|
|
|
|
|
id > 2 and id <= 4;
|
|
|
|
id = 6 and name = 'eric was here' and other > 'eeee';
|
|
|
|
remote: (`id` > 6 AND `name` > 'eric was here' AND `other` > 'eeee')
|
|
|
|
AND (`id` <= 6) AND ( AND `name` <= 'eric was here')
|
|
|
|
no results
|
|
|
|
records_in_range: start_key 3 end_key 3
|
|
|
|
read_range_first: start_key 3 end_key 3
|
|
|
|
|
|
|
|
Summary:
|
|
|
|
|
|
|
|
* If the start key flag is 0 the max key flag shouldn't even be set,
|
|
|
|
and if it is, the query produced would be invalid.
|
|
|
|
* Multipart keys, even if containing some or all numeric columns,
|
|
|
|
are treated the same as non-numeric keys
|
|
|
|
|
|
|
|
If the query is " = " (quotes or not):
|
|
|
|
- records in range start key flag HA_READ_KEY_EXACT,
|
|
|
|
end key flag HA_READ_AFTER_KEY (incorrect)
|
|
|
|
- any other: start key flag HA_READ_KEY_OR_NEXT,
|
|
|
|
end key flag HA_READ_AFTER_KEY (correct)
|
|
|
|
|
|
|
|
* 'like' queries (of key)
|
|
|
|
- Numeric, full table scan
|
|
|
|
- Non-numeric
|
|
|
|
records_in_range: start_key 0 end_key 3
|
|
|
|
other : start_key 1 end_key 3
|
|
|
|
|
|
|
|
* If the key flag is HA_READ_AFTER_KEY:
|
|
|
|
if start_key, append >
|
|
|
|
if end_key, append <=
|
|
|
|
|
|
|
|
* If create_where_key was called by records_in_range:
|
|
|
|
|
|
|
|
- if the key is numeric:
|
|
|
|
start key flag is 0 when end key is NULL, end key flag is 3 or 4
|
|
|
|
- if create_where_key was called by any other function:
|
|
|
|
start key flag is 1 when end key is NULL, end key flag is 3 or 4
|
|
|
|
- if the key is non-numeric, or multipart
|
|
|
|
When the query is an exact match, the start key flag is 0,
|
|
|
|
end key flag is 3 for what should be a no-range condition where
|
|
|
|
you should have 0 and max key NULL, which it is if called by
|
|
|
|
read_range_first
|
|
|
|
|
|
|
|
Conclusion:
|
|
|
|
|
|
|
|
1. Need logic to determin if a key is min or max when the flag is
|
|
|
|
HA_READ_AFTER_KEY, and handle appending correct operator accordingly
|
|
|
|
|
|
|
|
2. Need a boolean flag to pass to create_where_from_key, used in the
|
|
|
|
switch statement. Add 1 to the flag if:
|
|
|
|
- start key flag is HA_READ_KEY_EXACT and the end key is NULL
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool ha_federatedx::create_where_from_key(String *to,
|
|
|
|
KEY *key_info,
|
|
|
|
const key_range *start_key,
|
|
|
|
const key_range *end_key,
|
|
|
|
bool eq_range)
|
|
|
|
{
|
|
|
|
bool both_not_null=
|
|
|
|
(start_key != NULL && end_key != NULL) ? TRUE : FALSE;
|
|
|
|
const uchar *ptr;
|
|
|
|
uint remainder, length;
|
|
|
|
char tmpbuff[FEDERATEDX_QUERY_BUFFER_SIZE];
|
|
|
|
String tmp(tmpbuff, sizeof(tmpbuff), system_charset_info);
|
|
|
|
const key_range *ranges[2]= { start_key, end_key };
|
2018-05-14 10:47:13 +02:00
|
|
|
Time_zone *saved_time_zone= table->in_use->variables.time_zone;
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_ENTER("ha_federatedx::create_where_from_key");
|
|
|
|
|
|
|
|
tmp.length(0);
|
|
|
|
if (start_key == NULL && end_key == NULL)
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
|
2018-05-14 10:47:13 +02:00
|
|
|
table->in_use->variables.time_zone= UTC;
|
MDEV-17556 Assertion `bitmap_is_set_all(&table->s->all_set)' failed
The assertion failed in handler::ha_reset upon SELECT under
READ UNCOMMITTED from table with index on virtual column.
This was the debug-only failure, though the problem is mush wider:
* MY_BITMAP is a structure containing my_bitmap_map, the latter is a raw
bitmap.
* read_set, write_set and vcol_set of TABLE are the pointers to MY_BITMAP
* The rest of MY_BITMAPs are stored in TABLE and TABLE_SHARE
* The pointers to the stored MY_BITMAPs, like orig_read_set etc, and
sometimes all_set and tmp_set, are assigned to the pointers.
* Sometimes tmp_use_all_columns is used to substitute the raw bitmap
directly with all_set.bitmap
* Sometimes even bitmaps are directly modified, like in
TABLE::update_virtual_field(): bitmap_clear_all(&tmp_set) is called.
The last three bullets in the list, when used together (which is mostly
always) make the program flow cumbersome and impossible to follow,
notwithstanding the errors they cause, like this MDEV-17556, where tmp_set
pointer was assigned to read_set, write_set and vcol_set, then its bitmap
was substituted with all_set.bitmap by dbug_tmp_use_all_columns() call,
and then bitmap_clear_all(&tmp_set) was applied to all this.
To untangle this knot, the rule should be applied:
* Never substitute bitmaps! This patch is about this.
orig_*, all_set bitmaps are never substituted already.
This patch changes the following function prototypes:
* tmp_use_all_columns, dbug_tmp_use_all_columns
to accept MY_BITMAP** and to return MY_BITMAP * instead of my_bitmap_map*
* tmp_restore_column_map, dbug_tmp_restore_column_maps to accept
MY_BITMAP* instead of my_bitmap_map*
These functions now will substitute read_set/write_set/vcol_set directly,
and won't touch underlying bitmaps.
2020-12-29 04:38:16 +01:00
|
|
|
MY_BITMAP *old_map= dbug_tmp_use_all_columns(table, &table->write_set);
|
2009-10-30 19:50:56 +01:00
|
|
|
for (uint i= 0; i <= 1; i++)
|
|
|
|
{
|
|
|
|
KEY_PART_INFO *key_part;
|
|
|
|
if (ranges[i] == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (both_not_null)
|
|
|
|
{
|
|
|
|
if (i > 0)
|
|
|
|
tmp.append(STRING_WITH_LEN(") AND ("));
|
|
|
|
else
|
|
|
|
tmp.append(STRING_WITH_LEN(" ("));
|
|
|
|
}
|
|
|
|
|
2013-05-21 21:00:08 +02:00
|
|
|
for (key_part= key_info->key_part,
|
|
|
|
remainder= key_info->user_defined_key_parts,
|
|
|
|
length= ranges[i]->length,
|
|
|
|
ptr= ranges[i]->key; ;
|
2009-10-30 19:50:56 +01:00
|
|
|
remainder--,
|
2013-05-21 21:00:08 +02:00
|
|
|
key_part++)
|
2009-10-30 19:50:56 +01:00
|
|
|
{
|
|
|
|
Field *field= key_part->field;
|
|
|
|
uint store_length= key_part->store_length;
|
2013-03-25 23:03:13 +01:00
|
|
|
uint part_length= MY_MIN(store_length, length);
|
2022-01-01 16:25:48 +01:00
|
|
|
bool needs_quotes= field->str_needs_quotes();
|
2022-01-01 17:20:52 +01:00
|
|
|
bool reverse= key_part->key_part_flag & HA_REVERSE_SORT;
|
2022-01-01 16:25:48 +01:00
|
|
|
static const LEX_CSTRING lt={STRING_WITH_LEN(" < ") };
|
|
|
|
static const LEX_CSTRING gt={STRING_WITH_LEN(" > ") };
|
|
|
|
static const LEX_CSTRING le={STRING_WITH_LEN(" <= ") };
|
|
|
|
static const LEX_CSTRING ge={STRING_WITH_LEN(" >= ") };
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_DUMP("key, start of loop", ptr, length);
|
|
|
|
|
|
|
|
if (key_part->null_bit)
|
|
|
|
{
|
|
|
|
if (*ptr++)
|
|
|
|
{
|
Reduce usage of strlen()
Changes:
- To detect automatic strlen() I removed the methods in String that
uses 'const char *' without a length:
- String::append(const char*)
- Binary_string(const char *str)
- String(const char *str, CHARSET_INFO *cs)
- append_for_single_quote(const char *)
All usage of append(const char*) is changed to either use
String::append(char), String::append(const char*, size_t length) or
String::append(LEX_CSTRING)
- Added STRING_WITH_LEN() around constant string arguments to
String::append()
- Added overflow argument to escape_string_for_mysql() and
escape_quotes_for_mysql() instead of returning (size_t) -1 on overflow.
This was needed as most usage of the above functions never tested the
result for -1 and would have given wrong results or crashes in case
of overflows.
- Added Item_func_or_sum::func_name_cstring(), which returns LEX_CSTRING.
Changed all Item_func::func_name()'s to func_name_cstring()'s.
The old Item_func_or_sum::func_name() is now an inline function that
returns func_name_cstring().str.
- Changed Item::mode_name() and Item::func_name_ext() to return
LEX_CSTRING.
- Changed for some functions the name argument from const char * to
to const LEX_CSTRING &:
- Item::Item_func_fix_attributes()
- Item::check_type_...()
- Type_std_attributes::agg_item_collations()
- Type_std_attributes::agg_item_set_converter()
- Type_std_attributes::agg_arg_charsets...()
- Type_handler_hybrid_field_type::aggregate_for_result()
- Type_handler_geometry::check_type_geom_or_binary()
- Type_handler::Item_func_or_sum_illegal_param()
- Predicant_to_list_comparator::add_value_skip_null()
- Predicant_to_list_comparator::add_value()
- cmp_item_row::prepare_comparators()
- cmp_item_row::aggregate_row_elements_for_comparison()
- Cursor_ref::print_func()
- Removes String_space() as it was only used in one cases and that
could be simplified to not use String_space(), thanks to the fixed
my_vsnprintf().
- Added some const LEX_CSTRING's for common strings:
- NULL_clex_str, DATA_clex_str, INDEX_clex_str.
- Changed primary_key_name to a LEX_CSTRING
- Renamed String::set_quick() to String::set_buffer_if_not_allocated() to
clarify what the function really does.
- Rename of protocol function:
bool store(const char *from, CHARSET_INFO *cs) to
bool store_string_or_null(const char *from, CHARSET_INFO *cs).
This was done to both clarify the difference between this 'store' function
and also to make it easier to find unoptimal usage of store() calls.
- Added Protocol::store(const LEX_CSTRING*, CHARSET_INFO*)
- Changed some 'const char*' arrays to instead be of type LEX_CSTRING.
- class Item_func_units now used LEX_CSTRING for name.
Other things:
- Fixed a bug in mysql.cc:construct_prompt() where a wrong escape character
in the prompt would cause some part of the prompt to be duplicated.
- Fixed a lot of instances where the length of the argument to
append is known or easily obtain but was not used.
- Removed some not needed 'virtual' definition for functions that was
inherited from the parent. I added override to these.
- Fixed Ordered_key::print() to preallocate needed buffer. Old code could
case memory overruns.
- Simplified some loops when adding char * to a String with delimiters.
2020-08-12 19:29:55 +02:00
|
|
|
LEX_CSTRING constraint;
|
|
|
|
if (ranges[i]->flag == HA_READ_KEY_EXACT)
|
|
|
|
constraint= {STRING_WITH_LEN(" IS NULL ") };
|
|
|
|
else
|
|
|
|
constraint= {STRING_WITH_LEN(" IS NOT NULL ") };
|
2009-10-30 19:50:56 +01:00
|
|
|
/*
|
|
|
|
We got "IS [NOT] NULL" condition against nullable column. We
|
|
|
|
distinguish between "IS NOT NULL" and "IS NULL" by flag. For
|
|
|
|
"IS NULL", flag is set to HA_READ_KEY_EXACT.
|
|
|
|
*/
|
|
|
|
if (emit_key_part_name(&tmp, key_part) ||
|
Reduce usage of strlen()
Changes:
- To detect automatic strlen() I removed the methods in String that
uses 'const char *' without a length:
- String::append(const char*)
- Binary_string(const char *str)
- String(const char *str, CHARSET_INFO *cs)
- append_for_single_quote(const char *)
All usage of append(const char*) is changed to either use
String::append(char), String::append(const char*, size_t length) or
String::append(LEX_CSTRING)
- Added STRING_WITH_LEN() around constant string arguments to
String::append()
- Added overflow argument to escape_string_for_mysql() and
escape_quotes_for_mysql() instead of returning (size_t) -1 on overflow.
This was needed as most usage of the above functions never tested the
result for -1 and would have given wrong results or crashes in case
of overflows.
- Added Item_func_or_sum::func_name_cstring(), which returns LEX_CSTRING.
Changed all Item_func::func_name()'s to func_name_cstring()'s.
The old Item_func_or_sum::func_name() is now an inline function that
returns func_name_cstring().str.
- Changed Item::mode_name() and Item::func_name_ext() to return
LEX_CSTRING.
- Changed for some functions the name argument from const char * to
to const LEX_CSTRING &:
- Item::Item_func_fix_attributes()
- Item::check_type_...()
- Type_std_attributes::agg_item_collations()
- Type_std_attributes::agg_item_set_converter()
- Type_std_attributes::agg_arg_charsets...()
- Type_handler_hybrid_field_type::aggregate_for_result()
- Type_handler_geometry::check_type_geom_or_binary()
- Type_handler::Item_func_or_sum_illegal_param()
- Predicant_to_list_comparator::add_value_skip_null()
- Predicant_to_list_comparator::add_value()
- cmp_item_row::prepare_comparators()
- cmp_item_row::aggregate_row_elements_for_comparison()
- Cursor_ref::print_func()
- Removes String_space() as it was only used in one cases and that
could be simplified to not use String_space(), thanks to the fixed
my_vsnprintf().
- Added some const LEX_CSTRING's for common strings:
- NULL_clex_str, DATA_clex_str, INDEX_clex_str.
- Changed primary_key_name to a LEX_CSTRING
- Renamed String::set_quick() to String::set_buffer_if_not_allocated() to
clarify what the function really does.
- Rename of protocol function:
bool store(const char *from, CHARSET_INFO *cs) to
bool store_string_or_null(const char *from, CHARSET_INFO *cs).
This was done to both clarify the difference between this 'store' function
and also to make it easier to find unoptimal usage of store() calls.
- Added Protocol::store(const LEX_CSTRING*, CHARSET_INFO*)
- Changed some 'const char*' arrays to instead be of type LEX_CSTRING.
- class Item_func_units now used LEX_CSTRING for name.
Other things:
- Fixed a bug in mysql.cc:construct_prompt() where a wrong escape character
in the prompt would cause some part of the prompt to be duplicated.
- Fixed a lot of instances where the length of the argument to
append is known or easily obtain but was not used.
- Removed some not needed 'virtual' definition for functions that was
inherited from the parent. I added override to these.
- Fixed Ordered_key::print() to preallocate needed buffer. Old code could
case memory overruns.
- Simplified some loops when adding char * to a String with delimiters.
2020-08-12 19:29:55 +02:00
|
|
|
tmp.append(constraint))
|
2009-10-30 19:50:56 +01:00
|
|
|
goto err;
|
|
|
|
/*
|
|
|
|
We need to adjust pointer and length to be prepared for next
|
|
|
|
key part. As well as check if this was last key part.
|
|
|
|
*/
|
|
|
|
goto prepare_for_next_key_part;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tmp.append(STRING_WITH_LEN(" (")))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
switch (ranges[i]->flag) {
|
|
|
|
case HA_READ_KEY_EXACT:
|
|
|
|
DBUG_PRINT("info", ("federatedx HA_READ_KEY_EXACT %d", i));
|
|
|
|
if (store_length >= length ||
|
|
|
|
!needs_quotes ||
|
|
|
|
key_part->type == HA_KEYTYPE_BIT ||
|
|
|
|
field->result_type() != STRING_RESULT)
|
|
|
|
{
|
|
|
|
if (emit_key_part_name(&tmp, key_part))
|
|
|
|
goto err;
|
|
|
|
|
2022-01-01 16:25:48 +01:00
|
|
|
if (tmp.append(STRING_WITH_LEN(" = ")))
|
|
|
|
goto err;
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
if (emit_key_part_element(&tmp, key_part, needs_quotes, 0, ptr,
|
|
|
|
part_length))
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* LIKE */
|
|
|
|
if (emit_key_part_name(&tmp, key_part) ||
|
|
|
|
tmp.append(STRING_WITH_LEN(" LIKE ")) ||
|
|
|
|
emit_key_part_element(&tmp, key_part, needs_quotes, 1, ptr,
|
|
|
|
part_length))
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case HA_READ_AFTER_KEY:
|
|
|
|
if (eq_range)
|
|
|
|
{
|
Reduce usage of strlen()
Changes:
- To detect automatic strlen() I removed the methods in String that
uses 'const char *' without a length:
- String::append(const char*)
- Binary_string(const char *str)
- String(const char *str, CHARSET_INFO *cs)
- append_for_single_quote(const char *)
All usage of append(const char*) is changed to either use
String::append(char), String::append(const char*, size_t length) or
String::append(LEX_CSTRING)
- Added STRING_WITH_LEN() around constant string arguments to
String::append()
- Added overflow argument to escape_string_for_mysql() and
escape_quotes_for_mysql() instead of returning (size_t) -1 on overflow.
This was needed as most usage of the above functions never tested the
result for -1 and would have given wrong results or crashes in case
of overflows.
- Added Item_func_or_sum::func_name_cstring(), which returns LEX_CSTRING.
Changed all Item_func::func_name()'s to func_name_cstring()'s.
The old Item_func_or_sum::func_name() is now an inline function that
returns func_name_cstring().str.
- Changed Item::mode_name() and Item::func_name_ext() to return
LEX_CSTRING.
- Changed for some functions the name argument from const char * to
to const LEX_CSTRING &:
- Item::Item_func_fix_attributes()
- Item::check_type_...()
- Type_std_attributes::agg_item_collations()
- Type_std_attributes::agg_item_set_converter()
- Type_std_attributes::agg_arg_charsets...()
- Type_handler_hybrid_field_type::aggregate_for_result()
- Type_handler_geometry::check_type_geom_or_binary()
- Type_handler::Item_func_or_sum_illegal_param()
- Predicant_to_list_comparator::add_value_skip_null()
- Predicant_to_list_comparator::add_value()
- cmp_item_row::prepare_comparators()
- cmp_item_row::aggregate_row_elements_for_comparison()
- Cursor_ref::print_func()
- Removes String_space() as it was only used in one cases and that
could be simplified to not use String_space(), thanks to the fixed
my_vsnprintf().
- Added some const LEX_CSTRING's for common strings:
- NULL_clex_str, DATA_clex_str, INDEX_clex_str.
- Changed primary_key_name to a LEX_CSTRING
- Renamed String::set_quick() to String::set_buffer_if_not_allocated() to
clarify what the function really does.
- Rename of protocol function:
bool store(const char *from, CHARSET_INFO *cs) to
bool store_string_or_null(const char *from, CHARSET_INFO *cs).
This was done to both clarify the difference between this 'store' function
and also to make it easier to find unoptimal usage of store() calls.
- Added Protocol::store(const LEX_CSTRING*, CHARSET_INFO*)
- Changed some 'const char*' arrays to instead be of type LEX_CSTRING.
- class Item_func_units now used LEX_CSTRING for name.
Other things:
- Fixed a bug in mysql.cc:construct_prompt() where a wrong escape character
in the prompt would cause some part of the prompt to be duplicated.
- Fixed a lot of instances where the length of the argument to
append is known or easily obtain but was not used.
- Removed some not needed 'virtual' definition for functions that was
inherited from the parent. I added override to these.
- Fixed Ordered_key::print() to preallocate needed buffer. Old code could
case memory overruns.
- Simplified some loops when adding char * to a String with delimiters.
2020-08-12 19:29:55 +02:00
|
|
|
if (tmp.append(STRING_WITH_LEN("1=1"))) // Dummy
|
2009-10-30 19:50:56 +01:00
|
|
|
goto err;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DBUG_PRINT("info", ("federatedx HA_READ_AFTER_KEY %d", i));
|
2016-04-25 00:13:06 +02:00
|
|
|
if (store_length >= length || i > 0) /* end key */
|
2009-10-30 19:50:56 +01:00
|
|
|
{
|
|
|
|
if (emit_key_part_name(&tmp, key_part))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
if (i > 0) /* end key */
|
|
|
|
{
|
2022-01-01 17:20:52 +01:00
|
|
|
if (tmp.append(reverse ? ge : le))
|
2009-10-30 19:50:56 +01:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
else /* start key */
|
|
|
|
{
|
2022-01-01 17:20:52 +01:00
|
|
|
if (tmp.append(reverse ? lt : gt))
|
2009-10-30 19:50:56 +01:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (emit_key_part_element(&tmp, key_part, needs_quotes, 0, ptr,
|
|
|
|
part_length))
|
|
|
|
{
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-07-19 19:46:07 +02:00
|
|
|
/* fall through */
|
2009-10-30 19:50:56 +01:00
|
|
|
case HA_READ_KEY_OR_NEXT:
|
|
|
|
DBUG_PRINT("info", ("federatedx HA_READ_KEY_OR_NEXT %d", i));
|
|
|
|
if (emit_key_part_name(&tmp, key_part) ||
|
2022-01-01 17:20:52 +01:00
|
|
|
tmp.append(reverse ? le : ge) ||
|
2009-10-30 19:50:56 +01:00
|
|
|
emit_key_part_element(&tmp, key_part, needs_quotes, 0, ptr,
|
|
|
|
part_length))
|
|
|
|
goto err;
|
|
|
|
break;
|
|
|
|
case HA_READ_BEFORE_KEY:
|
|
|
|
DBUG_PRINT("info", ("federatedx HA_READ_BEFORE_KEY %d", i));
|
|
|
|
if (store_length >= length)
|
|
|
|
{
|
|
|
|
if (emit_key_part_name(&tmp, key_part) ||
|
2022-01-01 17:20:52 +01:00
|
|
|
tmp.append(reverse ? gt : lt) ||
|
2009-10-30 19:50:56 +01:00
|
|
|
emit_key_part_element(&tmp, key_part, needs_quotes, 0, ptr,
|
|
|
|
part_length))
|
|
|
|
goto err;
|
|
|
|
break;
|
|
|
|
}
|
2017-07-19 19:46:07 +02:00
|
|
|
/* fall through */
|
2009-10-30 19:50:56 +01:00
|
|
|
case HA_READ_KEY_OR_PREV:
|
|
|
|
DBUG_PRINT("info", ("federatedx HA_READ_KEY_OR_PREV %d", i));
|
|
|
|
if (emit_key_part_name(&tmp, key_part) ||
|
2022-01-01 17:20:52 +01:00
|
|
|
tmp.append(reverse ? ge : le) ||
|
2009-10-30 19:50:56 +01:00
|
|
|
emit_key_part_element(&tmp, key_part, needs_quotes, 0, ptr,
|
|
|
|
part_length))
|
|
|
|
goto err;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DBUG_PRINT("info",("cannot handle flag %d", ranges[i]->flag));
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
if (tmp.append(STRING_WITH_LEN(") ")))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
prepare_for_next_key_part:
|
|
|
|
if (store_length >= length)
|
|
|
|
break;
|
|
|
|
DBUG_PRINT("info", ("remainder %d", remainder));
|
|
|
|
DBUG_ASSERT(remainder > 1);
|
|
|
|
length-= store_length;
|
|
|
|
/*
|
|
|
|
For nullable columns, null-byte is already skipped before, that is
|
|
|
|
ptr was incremented by 1. Since store_length still counts null-byte,
|
|
|
|
we need to subtract 1 from store_length.
|
|
|
|
*/
|
2014-02-19 11:05:15 +01:00
|
|
|
ptr+= store_length - MY_TEST(key_part->null_bit);
|
2009-10-30 19:50:56 +01:00
|
|
|
if (tmp.append(STRING_WITH_LEN(" AND ")))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
DBUG_PRINT("info",
|
|
|
|
("create_where_from_key WHERE clause: %s",
|
|
|
|
tmp.c_ptr_quick()));
|
|
|
|
}
|
|
|
|
}
|
MDEV-17556 Assertion `bitmap_is_set_all(&table->s->all_set)' failed
The assertion failed in handler::ha_reset upon SELECT under
READ UNCOMMITTED from table with index on virtual column.
This was the debug-only failure, though the problem is mush wider:
* MY_BITMAP is a structure containing my_bitmap_map, the latter is a raw
bitmap.
* read_set, write_set and vcol_set of TABLE are the pointers to MY_BITMAP
* The rest of MY_BITMAPs are stored in TABLE and TABLE_SHARE
* The pointers to the stored MY_BITMAPs, like orig_read_set etc, and
sometimes all_set and tmp_set, are assigned to the pointers.
* Sometimes tmp_use_all_columns is used to substitute the raw bitmap
directly with all_set.bitmap
* Sometimes even bitmaps are directly modified, like in
TABLE::update_virtual_field(): bitmap_clear_all(&tmp_set) is called.
The last three bullets in the list, when used together (which is mostly
always) make the program flow cumbersome and impossible to follow,
notwithstanding the errors they cause, like this MDEV-17556, where tmp_set
pointer was assigned to read_set, write_set and vcol_set, then its bitmap
was substituted with all_set.bitmap by dbug_tmp_use_all_columns() call,
and then bitmap_clear_all(&tmp_set) was applied to all this.
To untangle this knot, the rule should be applied:
* Never substitute bitmaps! This patch is about this.
orig_*, all_set bitmaps are never substituted already.
This patch changes the following function prototypes:
* tmp_use_all_columns, dbug_tmp_use_all_columns
to accept MY_BITMAP** and to return MY_BITMAP * instead of my_bitmap_map*
* tmp_restore_column_map, dbug_tmp_restore_column_maps to accept
MY_BITMAP* instead of my_bitmap_map*
These functions now will substitute read_set/write_set/vcol_set directly,
and won't touch underlying bitmaps.
2020-12-29 04:38:16 +01:00
|
|
|
dbug_tmp_restore_column_map(&table->write_set, old_map);
|
2018-05-14 10:47:13 +02:00
|
|
|
table->in_use->variables.time_zone= saved_time_zone;
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
if (both_not_null)
|
|
|
|
if (tmp.append(STRING_WITH_LEN(") ")))
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
|
|
|
|
if (to->append(STRING_WITH_LEN(" WHERE ")))
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
|
|
|
|
if (to->append(tmp))
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
|
|
|
|
err:
|
MDEV-17556 Assertion `bitmap_is_set_all(&table->s->all_set)' failed
The assertion failed in handler::ha_reset upon SELECT under
READ UNCOMMITTED from table with index on virtual column.
This was the debug-only failure, though the problem is mush wider:
* MY_BITMAP is a structure containing my_bitmap_map, the latter is a raw
bitmap.
* read_set, write_set and vcol_set of TABLE are the pointers to MY_BITMAP
* The rest of MY_BITMAPs are stored in TABLE and TABLE_SHARE
* The pointers to the stored MY_BITMAPs, like orig_read_set etc, and
sometimes all_set and tmp_set, are assigned to the pointers.
* Sometimes tmp_use_all_columns is used to substitute the raw bitmap
directly with all_set.bitmap
* Sometimes even bitmaps are directly modified, like in
TABLE::update_virtual_field(): bitmap_clear_all(&tmp_set) is called.
The last three bullets in the list, when used together (which is mostly
always) make the program flow cumbersome and impossible to follow,
notwithstanding the errors they cause, like this MDEV-17556, where tmp_set
pointer was assigned to read_set, write_set and vcol_set, then its bitmap
was substituted with all_set.bitmap by dbug_tmp_use_all_columns() call,
and then bitmap_clear_all(&tmp_set) was applied to all this.
To untangle this knot, the rule should be applied:
* Never substitute bitmaps! This patch is about this.
orig_*, all_set bitmaps are never substituted already.
This patch changes the following function prototypes:
* tmp_use_all_columns, dbug_tmp_use_all_columns
to accept MY_BITMAP** and to return MY_BITMAP * instead of my_bitmap_map*
* tmp_restore_column_map, dbug_tmp_restore_column_maps to accept
MY_BITMAP* instead of my_bitmap_map*
These functions now will substitute read_set/write_set/vcol_set directly,
and won't touch underlying bitmaps.
2020-12-29 04:38:16 +01:00
|
|
|
dbug_tmp_restore_column_map(&table->write_set, old_map);
|
2018-05-14 10:47:13 +02:00
|
|
|
table->in_use->variables.time_zone= saved_time_zone;
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fill_server(MEM_ROOT *mem_root, FEDERATEDX_SERVER *server,
|
|
|
|
FEDERATEDX_SHARE *share, CHARSET_INFO *table_charset)
|
|
|
|
{
|
|
|
|
char buffer[STRING_BUFFER_USUAL_SIZE];
|
Reduce usage of strlen()
Changes:
- To detect automatic strlen() I removed the methods in String that
uses 'const char *' without a length:
- String::append(const char*)
- Binary_string(const char *str)
- String(const char *str, CHARSET_INFO *cs)
- append_for_single_quote(const char *)
All usage of append(const char*) is changed to either use
String::append(char), String::append(const char*, size_t length) or
String::append(LEX_CSTRING)
- Added STRING_WITH_LEN() around constant string arguments to
String::append()
- Added overflow argument to escape_string_for_mysql() and
escape_quotes_for_mysql() instead of returning (size_t) -1 on overflow.
This was needed as most usage of the above functions never tested the
result for -1 and would have given wrong results or crashes in case
of overflows.
- Added Item_func_or_sum::func_name_cstring(), which returns LEX_CSTRING.
Changed all Item_func::func_name()'s to func_name_cstring()'s.
The old Item_func_or_sum::func_name() is now an inline function that
returns func_name_cstring().str.
- Changed Item::mode_name() and Item::func_name_ext() to return
LEX_CSTRING.
- Changed for some functions the name argument from const char * to
to const LEX_CSTRING &:
- Item::Item_func_fix_attributes()
- Item::check_type_...()
- Type_std_attributes::agg_item_collations()
- Type_std_attributes::agg_item_set_converter()
- Type_std_attributes::agg_arg_charsets...()
- Type_handler_hybrid_field_type::aggregate_for_result()
- Type_handler_geometry::check_type_geom_or_binary()
- Type_handler::Item_func_or_sum_illegal_param()
- Predicant_to_list_comparator::add_value_skip_null()
- Predicant_to_list_comparator::add_value()
- cmp_item_row::prepare_comparators()
- cmp_item_row::aggregate_row_elements_for_comparison()
- Cursor_ref::print_func()
- Removes String_space() as it was only used in one cases and that
could be simplified to not use String_space(), thanks to the fixed
my_vsnprintf().
- Added some const LEX_CSTRING's for common strings:
- NULL_clex_str, DATA_clex_str, INDEX_clex_str.
- Changed primary_key_name to a LEX_CSTRING
- Renamed String::set_quick() to String::set_buffer_if_not_allocated() to
clarify what the function really does.
- Rename of protocol function:
bool store(const char *from, CHARSET_INFO *cs) to
bool store_string_or_null(const char *from, CHARSET_INFO *cs).
This was done to both clarify the difference between this 'store' function
and also to make it easier to find unoptimal usage of store() calls.
- Added Protocol::store(const LEX_CSTRING*, CHARSET_INFO*)
- Changed some 'const char*' arrays to instead be of type LEX_CSTRING.
- class Item_func_units now used LEX_CSTRING for name.
Other things:
- Fixed a bug in mysql.cc:construct_prompt() where a wrong escape character
in the prompt would cause some part of the prompt to be duplicated.
- Fixed a lot of instances where the length of the argument to
append is known or easily obtain but was not used.
- Removed some not needed 'virtual' definition for functions that was
inherited from the parent. I added override to these.
- Fixed Ordered_key::print() to preallocate needed buffer. Old code could
case memory overruns.
- Simplified some loops when adding char * to a String with delimiters.
2020-08-12 19:29:55 +02:00
|
|
|
const char *socket_arg= share->socket ? share->socket : "";
|
|
|
|
const char *password_arg= share->password ? share->password : "";
|
2023-06-23 11:24:02 +02:00
|
|
|
const Lex_cstring_strlen ls_database(share->database);
|
|
|
|
const Lex_cstring_strlen ls_socket(socket_arg);
|
Reduce usage of strlen()
Changes:
- To detect automatic strlen() I removed the methods in String that
uses 'const char *' without a length:
- String::append(const char*)
- Binary_string(const char *str)
- String(const char *str, CHARSET_INFO *cs)
- append_for_single_quote(const char *)
All usage of append(const char*) is changed to either use
String::append(char), String::append(const char*, size_t length) or
String::append(LEX_CSTRING)
- Added STRING_WITH_LEN() around constant string arguments to
String::append()
- Added overflow argument to escape_string_for_mysql() and
escape_quotes_for_mysql() instead of returning (size_t) -1 on overflow.
This was needed as most usage of the above functions never tested the
result for -1 and would have given wrong results or crashes in case
of overflows.
- Added Item_func_or_sum::func_name_cstring(), which returns LEX_CSTRING.
Changed all Item_func::func_name()'s to func_name_cstring()'s.
The old Item_func_or_sum::func_name() is now an inline function that
returns func_name_cstring().str.
- Changed Item::mode_name() and Item::func_name_ext() to return
LEX_CSTRING.
- Changed for some functions the name argument from const char * to
to const LEX_CSTRING &:
- Item::Item_func_fix_attributes()
- Item::check_type_...()
- Type_std_attributes::agg_item_collations()
- Type_std_attributes::agg_item_set_converter()
- Type_std_attributes::agg_arg_charsets...()
- Type_handler_hybrid_field_type::aggregate_for_result()
- Type_handler_geometry::check_type_geom_or_binary()
- Type_handler::Item_func_or_sum_illegal_param()
- Predicant_to_list_comparator::add_value_skip_null()
- Predicant_to_list_comparator::add_value()
- cmp_item_row::prepare_comparators()
- cmp_item_row::aggregate_row_elements_for_comparison()
- Cursor_ref::print_func()
- Removes String_space() as it was only used in one cases and that
could be simplified to not use String_space(), thanks to the fixed
my_vsnprintf().
- Added some const LEX_CSTRING's for common strings:
- NULL_clex_str, DATA_clex_str, INDEX_clex_str.
- Changed primary_key_name to a LEX_CSTRING
- Renamed String::set_quick() to String::set_buffer_if_not_allocated() to
clarify what the function really does.
- Rename of protocol function:
bool store(const char *from, CHARSET_INFO *cs) to
bool store_string_or_null(const char *from, CHARSET_INFO *cs).
This was done to both clarify the difference between this 'store' function
and also to make it easier to find unoptimal usage of store() calls.
- Added Protocol::store(const LEX_CSTRING*, CHARSET_INFO*)
- Changed some 'const char*' arrays to instead be of type LEX_CSTRING.
- class Item_func_units now used LEX_CSTRING for name.
Other things:
- Fixed a bug in mysql.cc:construct_prompt() where a wrong escape character
in the prompt would cause some part of the prompt to be duplicated.
- Fixed a lot of instances where the length of the argument to
append is known or easily obtain but was not used.
- Removed some not needed 'virtual' definition for functions that was
inherited from the parent. I added override to these.
- Fixed Ordered_key::print() to preallocate needed buffer. Old code could
case memory overruns.
- Simplified some loops when adding char * to a String with delimiters.
2020-08-12 19:29:55 +02:00
|
|
|
|
2009-10-30 19:50:56 +01:00
|
|
|
String key(buffer, sizeof(buffer), &my_charset_bin);
|
2023-06-23 11:24:02 +02:00
|
|
|
String scheme, hostname;
|
|
|
|
String database(ls_database.str, ls_database.length, system_charset_info);
|
Reduce usage of strlen()
Changes:
- To detect automatic strlen() I removed the methods in String that
uses 'const char *' without a length:
- String::append(const char*)
- Binary_string(const char *str)
- String(const char *str, CHARSET_INFO *cs)
- append_for_single_quote(const char *)
All usage of append(const char*) is changed to either use
String::append(char), String::append(const char*, size_t length) or
String::append(LEX_CSTRING)
- Added STRING_WITH_LEN() around constant string arguments to
String::append()
- Added overflow argument to escape_string_for_mysql() and
escape_quotes_for_mysql() instead of returning (size_t) -1 on overflow.
This was needed as most usage of the above functions never tested the
result for -1 and would have given wrong results or crashes in case
of overflows.
- Added Item_func_or_sum::func_name_cstring(), which returns LEX_CSTRING.
Changed all Item_func::func_name()'s to func_name_cstring()'s.
The old Item_func_or_sum::func_name() is now an inline function that
returns func_name_cstring().str.
- Changed Item::mode_name() and Item::func_name_ext() to return
LEX_CSTRING.
- Changed for some functions the name argument from const char * to
to const LEX_CSTRING &:
- Item::Item_func_fix_attributes()
- Item::check_type_...()
- Type_std_attributes::agg_item_collations()
- Type_std_attributes::agg_item_set_converter()
- Type_std_attributes::agg_arg_charsets...()
- Type_handler_hybrid_field_type::aggregate_for_result()
- Type_handler_geometry::check_type_geom_or_binary()
- Type_handler::Item_func_or_sum_illegal_param()
- Predicant_to_list_comparator::add_value_skip_null()
- Predicant_to_list_comparator::add_value()
- cmp_item_row::prepare_comparators()
- cmp_item_row::aggregate_row_elements_for_comparison()
- Cursor_ref::print_func()
- Removes String_space() as it was only used in one cases and that
could be simplified to not use String_space(), thanks to the fixed
my_vsnprintf().
- Added some const LEX_CSTRING's for common strings:
- NULL_clex_str, DATA_clex_str, INDEX_clex_str.
- Changed primary_key_name to a LEX_CSTRING
- Renamed String::set_quick() to String::set_buffer_if_not_allocated() to
clarify what the function really does.
- Rename of protocol function:
bool store(const char *from, CHARSET_INFO *cs) to
bool store_string_or_null(const char *from, CHARSET_INFO *cs).
This was done to both clarify the difference between this 'store' function
and also to make it easier to find unoptimal usage of store() calls.
- Added Protocol::store(const LEX_CSTRING*, CHARSET_INFO*)
- Changed some 'const char*' arrays to instead be of type LEX_CSTRING.
- class Item_func_units now used LEX_CSTRING for name.
Other things:
- Fixed a bug in mysql.cc:construct_prompt() where a wrong escape character
in the prompt would cause some part of the prompt to be duplicated.
- Fixed a lot of instances where the length of the argument to
append is known or easily obtain but was not used.
- Removed some not needed 'virtual' definition for functions that was
inherited from the parent. I added override to these.
- Fixed Ordered_key::print() to preallocate needed buffer. Old code could
case memory overruns.
- Simplified some loops when adding char * to a String with delimiters.
2020-08-12 19:29:55 +02:00
|
|
|
String username(share->username, strlen(share->username), system_charset_info);
|
2023-06-23 11:24:02 +02:00
|
|
|
String socket(ls_socket.str, ls_socket.length, files_charset_info);
|
Reduce usage of strlen()
Changes:
- To detect automatic strlen() I removed the methods in String that
uses 'const char *' without a length:
- String::append(const char*)
- Binary_string(const char *str)
- String(const char *str, CHARSET_INFO *cs)
- append_for_single_quote(const char *)
All usage of append(const char*) is changed to either use
String::append(char), String::append(const char*, size_t length) or
String::append(LEX_CSTRING)
- Added STRING_WITH_LEN() around constant string arguments to
String::append()
- Added overflow argument to escape_string_for_mysql() and
escape_quotes_for_mysql() instead of returning (size_t) -1 on overflow.
This was needed as most usage of the above functions never tested the
result for -1 and would have given wrong results or crashes in case
of overflows.
- Added Item_func_or_sum::func_name_cstring(), which returns LEX_CSTRING.
Changed all Item_func::func_name()'s to func_name_cstring()'s.
The old Item_func_or_sum::func_name() is now an inline function that
returns func_name_cstring().str.
- Changed Item::mode_name() and Item::func_name_ext() to return
LEX_CSTRING.
- Changed for some functions the name argument from const char * to
to const LEX_CSTRING &:
- Item::Item_func_fix_attributes()
- Item::check_type_...()
- Type_std_attributes::agg_item_collations()
- Type_std_attributes::agg_item_set_converter()
- Type_std_attributes::agg_arg_charsets...()
- Type_handler_hybrid_field_type::aggregate_for_result()
- Type_handler_geometry::check_type_geom_or_binary()
- Type_handler::Item_func_or_sum_illegal_param()
- Predicant_to_list_comparator::add_value_skip_null()
- Predicant_to_list_comparator::add_value()
- cmp_item_row::prepare_comparators()
- cmp_item_row::aggregate_row_elements_for_comparison()
- Cursor_ref::print_func()
- Removes String_space() as it was only used in one cases and that
could be simplified to not use String_space(), thanks to the fixed
my_vsnprintf().
- Added some const LEX_CSTRING's for common strings:
- NULL_clex_str, DATA_clex_str, INDEX_clex_str.
- Changed primary_key_name to a LEX_CSTRING
- Renamed String::set_quick() to String::set_buffer_if_not_allocated() to
clarify what the function really does.
- Rename of protocol function:
bool store(const char *from, CHARSET_INFO *cs) to
bool store_string_or_null(const char *from, CHARSET_INFO *cs).
This was done to both clarify the difference between this 'store' function
and also to make it easier to find unoptimal usage of store() calls.
- Added Protocol::store(const LEX_CSTRING*, CHARSET_INFO*)
- Changed some 'const char*' arrays to instead be of type LEX_CSTRING.
- class Item_func_units now used LEX_CSTRING for name.
Other things:
- Fixed a bug in mysql.cc:construct_prompt() where a wrong escape character
in the prompt would cause some part of the prompt to be duplicated.
- Fixed a lot of instances where the length of the argument to
append is known or easily obtain but was not used.
- Removed some not needed 'virtual' definition for functions that was
inherited from the parent. I added override to these.
- Fixed Ordered_key::print() to preallocate needed buffer. Old code could
case memory overruns.
- Simplified some loops when adding char * to a String with delimiters.
2020-08-12 19:29:55 +02:00
|
|
|
String password(password_arg, strlen(password_arg), &my_charset_bin);
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_ENTER("fill_server");
|
|
|
|
|
|
|
|
/* Do some case conversions */
|
2023-06-23 11:24:02 +02:00
|
|
|
scheme.copy_casedn(&my_charset_latin1, Lex_cstring_strlen(share->scheme));
|
|
|
|
hostname.copy_casedn(&my_charset_latin1, Lex_cstring_strlen(share->hostname));
|
|
|
|
|
2009-10-30 19:50:56 +01:00
|
|
|
if (lower_case_table_names)
|
2023-06-23 11:24:02 +02:00
|
|
|
database.copy_casedn(system_charset_info, ls_database);
|
2009-11-03 12:08:09 +01:00
|
|
|
|
2021-06-06 13:21:03 +02:00
|
|
|
#ifndef _WIN32
|
2009-11-03 12:08:09 +01:00
|
|
|
/*
|
|
|
|
TODO: there is no unix sockets under windows so the engine should be
|
|
|
|
revised about using sockets in such environment.
|
|
|
|
*/
|
2009-10-30 19:50:56 +01:00
|
|
|
if (lower_case_file_system && socket.length())
|
2023-06-23 11:24:02 +02:00
|
|
|
socket.copy_casedn(files_charset_info, ls_socket);
|
2009-11-03 12:08:09 +01:00
|
|
|
#endif
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
/* start with all bytes zeroed */
|
|
|
|
bzero(server, sizeof(*server));
|
|
|
|
|
|
|
|
key.length(0);
|
|
|
|
key.reserve(scheme.length() + hostname.length() + database.length() +
|
|
|
|
socket.length() + username.length() + password.length() +
|
|
|
|
sizeof(int) + 8);
|
|
|
|
key.append(scheme);
|
|
|
|
key.q_append('\0');
|
|
|
|
server->hostname= (const char *) (intptr) key.length();
|
|
|
|
key.append(hostname);
|
|
|
|
key.q_append('\0');
|
|
|
|
server->database= (const char *) (intptr) key.length();
|
|
|
|
key.append(database);
|
|
|
|
key.q_append('\0');
|
|
|
|
key.q_append((uint32) share->port);
|
|
|
|
server->socket= (const char *) (intptr) key.length();
|
|
|
|
key.append(socket);
|
|
|
|
key.q_append('\0');
|
|
|
|
server->username= (const char *) (intptr) key.length();
|
|
|
|
key.append(username);
|
|
|
|
key.q_append('\0');
|
|
|
|
server->password= (const char *) (intptr) key.length();
|
|
|
|
key.append(password);
|
2010-11-23 23:08:48 +01:00
|
|
|
key.c_ptr_safe(); // Ensure we have end \0
|
|
|
|
|
2009-10-30 19:50:56 +01:00
|
|
|
server->key_length= key.length();
|
2011-02-28 18:39:30 +01:00
|
|
|
/* Copy and add end \0 */
|
|
|
|
server->key= (uchar *) strmake_root(mem_root, key.ptr(), key.length());
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
/* pointer magic */
|
|
|
|
server->scheme+= (intptr) server->key;
|
|
|
|
server->hostname+= (intptr) server->key;
|
|
|
|
server->database+= (intptr) server->key;
|
|
|
|
server->username+= (intptr) server->key;
|
|
|
|
server->password+= (intptr) server->key;
|
|
|
|
server->socket+= (intptr) server->key;
|
|
|
|
server->port= share->port;
|
|
|
|
|
|
|
|
if (!share->socket)
|
|
|
|
server->socket= NULL;
|
|
|
|
if (!share->password)
|
|
|
|
server->password= NULL;
|
|
|
|
|
|
|
|
if (table_charset)
|
2020-08-22 01:08:59 +02:00
|
|
|
server->csname= strdup_root(mem_root, table_charset->cs_name.str);
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static FEDERATEDX_SERVER *get_server(FEDERATEDX_SHARE *share, TABLE *table)
|
|
|
|
{
|
|
|
|
FEDERATEDX_SERVER *server= NULL, tmp_server;
|
|
|
|
MEM_ROOT mem_root;
|
|
|
|
char buffer[STRING_BUFFER_USUAL_SIZE];
|
Reduce usage of strlen()
Changes:
- To detect automatic strlen() I removed the methods in String that
uses 'const char *' without a length:
- String::append(const char*)
- Binary_string(const char *str)
- String(const char *str, CHARSET_INFO *cs)
- append_for_single_quote(const char *)
All usage of append(const char*) is changed to either use
String::append(char), String::append(const char*, size_t length) or
String::append(LEX_CSTRING)
- Added STRING_WITH_LEN() around constant string arguments to
String::append()
- Added overflow argument to escape_string_for_mysql() and
escape_quotes_for_mysql() instead of returning (size_t) -1 on overflow.
This was needed as most usage of the above functions never tested the
result for -1 and would have given wrong results or crashes in case
of overflows.
- Added Item_func_or_sum::func_name_cstring(), which returns LEX_CSTRING.
Changed all Item_func::func_name()'s to func_name_cstring()'s.
The old Item_func_or_sum::func_name() is now an inline function that
returns func_name_cstring().str.
- Changed Item::mode_name() and Item::func_name_ext() to return
LEX_CSTRING.
- Changed for some functions the name argument from const char * to
to const LEX_CSTRING &:
- Item::Item_func_fix_attributes()
- Item::check_type_...()
- Type_std_attributes::agg_item_collations()
- Type_std_attributes::agg_item_set_converter()
- Type_std_attributes::agg_arg_charsets...()
- Type_handler_hybrid_field_type::aggregate_for_result()
- Type_handler_geometry::check_type_geom_or_binary()
- Type_handler::Item_func_or_sum_illegal_param()
- Predicant_to_list_comparator::add_value_skip_null()
- Predicant_to_list_comparator::add_value()
- cmp_item_row::prepare_comparators()
- cmp_item_row::aggregate_row_elements_for_comparison()
- Cursor_ref::print_func()
- Removes String_space() as it was only used in one cases and that
could be simplified to not use String_space(), thanks to the fixed
my_vsnprintf().
- Added some const LEX_CSTRING's for common strings:
- NULL_clex_str, DATA_clex_str, INDEX_clex_str.
- Changed primary_key_name to a LEX_CSTRING
- Renamed String::set_quick() to String::set_buffer_if_not_allocated() to
clarify what the function really does.
- Rename of protocol function:
bool store(const char *from, CHARSET_INFO *cs) to
bool store_string_or_null(const char *from, CHARSET_INFO *cs).
This was done to both clarify the difference between this 'store' function
and also to make it easier to find unoptimal usage of store() calls.
- Added Protocol::store(const LEX_CSTRING*, CHARSET_INFO*)
- Changed some 'const char*' arrays to instead be of type LEX_CSTRING.
- class Item_func_units now used LEX_CSTRING for name.
Other things:
- Fixed a bug in mysql.cc:construct_prompt() where a wrong escape character
in the prompt would cause some part of the prompt to be duplicated.
- Fixed a lot of instances where the length of the argument to
append is known or easily obtain but was not used.
- Removed some not needed 'virtual' definition for functions that was
inherited from the parent. I added override to these.
- Fixed Ordered_key::print() to preallocate needed buffer. Old code could
case memory overruns.
- Simplified some loops when adding char * to a String with delimiters.
2020-08-12 19:29:55 +02:00
|
|
|
const char *socket_arg= share->socket ? share->socket : "";
|
|
|
|
const char *password_arg= share->password ? share->password : "";
|
|
|
|
|
2009-10-30 19:50:56 +01:00
|
|
|
String key(buffer, sizeof(buffer), &my_charset_bin);
|
Reduce usage of strlen()
Changes:
- To detect automatic strlen() I removed the methods in String that
uses 'const char *' without a length:
- String::append(const char*)
- Binary_string(const char *str)
- String(const char *str, CHARSET_INFO *cs)
- append_for_single_quote(const char *)
All usage of append(const char*) is changed to either use
String::append(char), String::append(const char*, size_t length) or
String::append(LEX_CSTRING)
- Added STRING_WITH_LEN() around constant string arguments to
String::append()
- Added overflow argument to escape_string_for_mysql() and
escape_quotes_for_mysql() instead of returning (size_t) -1 on overflow.
This was needed as most usage of the above functions never tested the
result for -1 and would have given wrong results or crashes in case
of overflows.
- Added Item_func_or_sum::func_name_cstring(), which returns LEX_CSTRING.
Changed all Item_func::func_name()'s to func_name_cstring()'s.
The old Item_func_or_sum::func_name() is now an inline function that
returns func_name_cstring().str.
- Changed Item::mode_name() and Item::func_name_ext() to return
LEX_CSTRING.
- Changed for some functions the name argument from const char * to
to const LEX_CSTRING &:
- Item::Item_func_fix_attributes()
- Item::check_type_...()
- Type_std_attributes::agg_item_collations()
- Type_std_attributes::agg_item_set_converter()
- Type_std_attributes::agg_arg_charsets...()
- Type_handler_hybrid_field_type::aggregate_for_result()
- Type_handler_geometry::check_type_geom_or_binary()
- Type_handler::Item_func_or_sum_illegal_param()
- Predicant_to_list_comparator::add_value_skip_null()
- Predicant_to_list_comparator::add_value()
- cmp_item_row::prepare_comparators()
- cmp_item_row::aggregate_row_elements_for_comparison()
- Cursor_ref::print_func()
- Removes String_space() as it was only used in one cases and that
could be simplified to not use String_space(), thanks to the fixed
my_vsnprintf().
- Added some const LEX_CSTRING's for common strings:
- NULL_clex_str, DATA_clex_str, INDEX_clex_str.
- Changed primary_key_name to a LEX_CSTRING
- Renamed String::set_quick() to String::set_buffer_if_not_allocated() to
clarify what the function really does.
- Rename of protocol function:
bool store(const char *from, CHARSET_INFO *cs) to
bool store_string_or_null(const char *from, CHARSET_INFO *cs).
This was done to both clarify the difference between this 'store' function
and also to make it easier to find unoptimal usage of store() calls.
- Added Protocol::store(const LEX_CSTRING*, CHARSET_INFO*)
- Changed some 'const char*' arrays to instead be of type LEX_CSTRING.
- class Item_func_units now used LEX_CSTRING for name.
Other things:
- Fixed a bug in mysql.cc:construct_prompt() where a wrong escape character
in the prompt would cause some part of the prompt to be duplicated.
- Fixed a lot of instances where the length of the argument to
append is known or easily obtain but was not used.
- Removed some not needed 'virtual' definition for functions that was
inherited from the parent. I added override to these.
- Fixed Ordered_key::print() to preallocate needed buffer. Old code could
case memory overruns.
- Simplified some loops when adding char * to a String with delimiters.
2020-08-12 19:29:55 +02:00
|
|
|
String scheme(share->scheme, strlen(share->scheme), &my_charset_latin1);
|
|
|
|
String hostname(share->hostname, strlen(share->hostname), &my_charset_latin1);
|
|
|
|
String database(share->database, strlen(share->database), system_charset_info);
|
|
|
|
String username(share->username, strlen(share->username), system_charset_info);
|
|
|
|
String socket(socket_arg, strlen(socket_arg), files_charset_info);
|
|
|
|
String password(password_arg, strlen(password_arg), &my_charset_bin);
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_ENTER("ha_federated.cc::get_server");
|
|
|
|
|
2011-07-13 21:10:18 +02:00
|
|
|
mysql_mutex_assert_owner(&federatedx_mutex);
|
2009-10-30 19:50:56 +01:00
|
|
|
|
2020-01-29 13:50:26 +01:00
|
|
|
init_alloc_root(PSI_INSTRUMENT_ME, &mem_root, 4096, 4096, MYF(0));
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
fill_server(&mem_root, &tmp_server, share, table ? table->s->table_charset : 0);
|
|
|
|
|
2011-04-25 17:22:25 +02:00
|
|
|
if (!(server= (FEDERATEDX_SERVER *) my_hash_search(&federatedx_open_servers,
|
2009-10-30 19:50:56 +01:00
|
|
|
tmp_server.key,
|
|
|
|
tmp_server.key_length)))
|
|
|
|
{
|
|
|
|
if (!table || !tmp_server.csname)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!(server= (FEDERATEDX_SERVER *) memdup_root(&mem_root,
|
|
|
|
(char *) &tmp_server,
|
|
|
|
sizeof(*server))))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
server->mem_root= mem_root;
|
|
|
|
|
|
|
|
if (my_hash_insert(&federatedx_open_servers, (uchar*) server))
|
|
|
|
goto error;
|
|
|
|
|
2011-07-13 21:10:18 +02:00
|
|
|
mysql_mutex_init(fe_key_mutex_FEDERATEDX_SERVER_mutex,
|
|
|
|
&server->mutex, MY_MUTEX_INIT_FAST);
|
2009-10-30 19:50:56 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
free_root(&mem_root, MYF(0)); /* prevents memory leak */
|
|
|
|
|
|
|
|
server->use_count++;
|
|
|
|
|
|
|
|
DBUG_RETURN(server);
|
|
|
|
error:
|
|
|
|
free_root(&mem_root, MYF(0));
|
|
|
|
DBUG_RETURN(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Example of simple lock controls. The "share" it creates is structure we will
|
|
|
|
pass to each federatedx handler. Do you have to have one of these? Well, you
|
|
|
|
have pieces that are used for locking, and they are needed to function.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static FEDERATEDX_SHARE *get_share(const char *table_name, TABLE *table)
|
|
|
|
{
|
|
|
|
char query_buffer[FEDERATEDX_QUERY_BUFFER_SIZE];
|
|
|
|
Field **field;
|
|
|
|
String query(query_buffer, sizeof(query_buffer), &my_charset_bin);
|
|
|
|
FEDERATEDX_SHARE *share= NULL, tmp_share;
|
|
|
|
MEM_ROOT mem_root;
|
|
|
|
DBUG_ENTER("ha_federatedx.cc::get_share");
|
|
|
|
|
|
|
|
/*
|
|
|
|
In order to use this string, we must first zero it's length,
|
|
|
|
or it will contain garbage
|
|
|
|
*/
|
|
|
|
query.length(0);
|
|
|
|
|
|
|
|
bzero(&tmp_share, sizeof(tmp_share));
|
2020-01-29 13:50:26 +01:00
|
|
|
init_alloc_root(PSI_INSTRUMENT_ME, &mem_root, 256, 0, MYF(0));
|
2009-10-30 19:50:56 +01:00
|
|
|
|
2011-07-13 21:10:18 +02:00
|
|
|
mysql_mutex_lock(&federatedx_mutex);
|
2009-10-30 19:50:56 +01:00
|
|
|
|
2018-05-14 10:47:13 +02:00
|
|
|
if (unlikely(!UTC))
|
|
|
|
{
|
|
|
|
String tz_00_name(STRING_WITH_LEN("+00:00"), &my_charset_bin);
|
|
|
|
UTC= my_tz_find(current_thd, &tz_00_name);
|
|
|
|
}
|
|
|
|
|
2009-10-30 19:50:56 +01:00
|
|
|
tmp_share.share_key= table_name;
|
2018-02-06 13:55:58 +01:00
|
|
|
tmp_share.share_key_length= (int)strlen(table_name);
|
2013-04-09 16:19:18 +02:00
|
|
|
if (parse_url(&mem_root, &tmp_share, table->s, 0))
|
2009-10-30 19:50:56 +01:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* TODO: change tmp_share.scheme to LEX_STRING object */
|
2011-04-25 17:22:25 +02:00
|
|
|
if (!(share= (FEDERATEDX_SHARE *) my_hash_search(&federatedx_open_tables,
|
2009-10-30 19:50:56 +01:00
|
|
|
(uchar*) tmp_share.share_key,
|
|
|
|
tmp_share.
|
|
|
|
share_key_length)))
|
|
|
|
{
|
|
|
|
query.set_charset(system_charset_info);
|
|
|
|
query.append(STRING_WITH_LEN("SELECT "));
|
|
|
|
for (field= table->field; *field; field++)
|
|
|
|
{
|
2017-04-23 18:39:57 +02:00
|
|
|
append_ident(&query, (*field)->field_name.str,
|
|
|
|
(*field)->field_name.length, ident_quote_char);
|
2009-10-30 19:50:56 +01:00
|
|
|
query.append(STRING_WITH_LEN(", "));
|
|
|
|
}
|
|
|
|
/* chops off trailing comma */
|
|
|
|
query.length(query.length() - sizeof_trailing_comma);
|
|
|
|
|
|
|
|
query.append(STRING_WITH_LEN(" FROM "));
|
|
|
|
|
2017-04-23 18:39:57 +02:00
|
|
|
append_ident(&query, tmp_share.table_name,
|
2009-10-30 19:50:56 +01:00
|
|
|
tmp_share.table_name_length, ident_quote_char);
|
|
|
|
|
|
|
|
if (!(share= (FEDERATEDX_SHARE *) memdup_root(&mem_root, (char*)&tmp_share, sizeof(*share))) ||
|
2011-02-10 21:40:59 +01:00
|
|
|
!(share->share_key= (char*) memdup_root(&mem_root, tmp_share.share_key, tmp_share.share_key_length+1)) ||
|
Reduce usage of strlen()
Changes:
- To detect automatic strlen() I removed the methods in String that
uses 'const char *' without a length:
- String::append(const char*)
- Binary_string(const char *str)
- String(const char *str, CHARSET_INFO *cs)
- append_for_single_quote(const char *)
All usage of append(const char*) is changed to either use
String::append(char), String::append(const char*, size_t length) or
String::append(LEX_CSTRING)
- Added STRING_WITH_LEN() around constant string arguments to
String::append()
- Added overflow argument to escape_string_for_mysql() and
escape_quotes_for_mysql() instead of returning (size_t) -1 on overflow.
This was needed as most usage of the above functions never tested the
result for -1 and would have given wrong results or crashes in case
of overflows.
- Added Item_func_or_sum::func_name_cstring(), which returns LEX_CSTRING.
Changed all Item_func::func_name()'s to func_name_cstring()'s.
The old Item_func_or_sum::func_name() is now an inline function that
returns func_name_cstring().str.
- Changed Item::mode_name() and Item::func_name_ext() to return
LEX_CSTRING.
- Changed for some functions the name argument from const char * to
to const LEX_CSTRING &:
- Item::Item_func_fix_attributes()
- Item::check_type_...()
- Type_std_attributes::agg_item_collations()
- Type_std_attributes::agg_item_set_converter()
- Type_std_attributes::agg_arg_charsets...()
- Type_handler_hybrid_field_type::aggregate_for_result()
- Type_handler_geometry::check_type_geom_or_binary()
- Type_handler::Item_func_or_sum_illegal_param()
- Predicant_to_list_comparator::add_value_skip_null()
- Predicant_to_list_comparator::add_value()
- cmp_item_row::prepare_comparators()
- cmp_item_row::aggregate_row_elements_for_comparison()
- Cursor_ref::print_func()
- Removes String_space() as it was only used in one cases and that
could be simplified to not use String_space(), thanks to the fixed
my_vsnprintf().
- Added some const LEX_CSTRING's for common strings:
- NULL_clex_str, DATA_clex_str, INDEX_clex_str.
- Changed primary_key_name to a LEX_CSTRING
- Renamed String::set_quick() to String::set_buffer_if_not_allocated() to
clarify what the function really does.
- Rename of protocol function:
bool store(const char *from, CHARSET_INFO *cs) to
bool store_string_or_null(const char *from, CHARSET_INFO *cs).
This was done to both clarify the difference between this 'store' function
and also to make it easier to find unoptimal usage of store() calls.
- Added Protocol::store(const LEX_CSTRING*, CHARSET_INFO*)
- Changed some 'const char*' arrays to instead be of type LEX_CSTRING.
- class Item_func_units now used LEX_CSTRING for name.
Other things:
- Fixed a bug in mysql.cc:construct_prompt() where a wrong escape character
in the prompt would cause some part of the prompt to be duplicated.
- Fixed a lot of instances where the length of the argument to
append is known or easily obtain but was not used.
- Removed some not needed 'virtual' definition for functions that was
inherited from the parent. I added override to these.
- Fixed Ordered_key::print() to preallocate needed buffer. Old code could
case memory overruns.
- Simplified some loops when adding char * to a String with delimiters.
2020-08-12 19:29:55 +02:00
|
|
|
!(share->select_query.str= (char*) strmake_root(&mem_root, query.ptr(), query.length())))
|
2009-10-30 19:50:56 +01:00
|
|
|
goto error;
|
Reduce usage of strlen()
Changes:
- To detect automatic strlen() I removed the methods in String that
uses 'const char *' without a length:
- String::append(const char*)
- Binary_string(const char *str)
- String(const char *str, CHARSET_INFO *cs)
- append_for_single_quote(const char *)
All usage of append(const char*) is changed to either use
String::append(char), String::append(const char*, size_t length) or
String::append(LEX_CSTRING)
- Added STRING_WITH_LEN() around constant string arguments to
String::append()
- Added overflow argument to escape_string_for_mysql() and
escape_quotes_for_mysql() instead of returning (size_t) -1 on overflow.
This was needed as most usage of the above functions never tested the
result for -1 and would have given wrong results or crashes in case
of overflows.
- Added Item_func_or_sum::func_name_cstring(), which returns LEX_CSTRING.
Changed all Item_func::func_name()'s to func_name_cstring()'s.
The old Item_func_or_sum::func_name() is now an inline function that
returns func_name_cstring().str.
- Changed Item::mode_name() and Item::func_name_ext() to return
LEX_CSTRING.
- Changed for some functions the name argument from const char * to
to const LEX_CSTRING &:
- Item::Item_func_fix_attributes()
- Item::check_type_...()
- Type_std_attributes::agg_item_collations()
- Type_std_attributes::agg_item_set_converter()
- Type_std_attributes::agg_arg_charsets...()
- Type_handler_hybrid_field_type::aggregate_for_result()
- Type_handler_geometry::check_type_geom_or_binary()
- Type_handler::Item_func_or_sum_illegal_param()
- Predicant_to_list_comparator::add_value_skip_null()
- Predicant_to_list_comparator::add_value()
- cmp_item_row::prepare_comparators()
- cmp_item_row::aggregate_row_elements_for_comparison()
- Cursor_ref::print_func()
- Removes String_space() as it was only used in one cases and that
could be simplified to not use String_space(), thanks to the fixed
my_vsnprintf().
- Added some const LEX_CSTRING's for common strings:
- NULL_clex_str, DATA_clex_str, INDEX_clex_str.
- Changed primary_key_name to a LEX_CSTRING
- Renamed String::set_quick() to String::set_buffer_if_not_allocated() to
clarify what the function really does.
- Rename of protocol function:
bool store(const char *from, CHARSET_INFO *cs) to
bool store_string_or_null(const char *from, CHARSET_INFO *cs).
This was done to both clarify the difference between this 'store' function
and also to make it easier to find unoptimal usage of store() calls.
- Added Protocol::store(const LEX_CSTRING*, CHARSET_INFO*)
- Changed some 'const char*' arrays to instead be of type LEX_CSTRING.
- class Item_func_units now used LEX_CSTRING for name.
Other things:
- Fixed a bug in mysql.cc:construct_prompt() where a wrong escape character
in the prompt would cause some part of the prompt to be duplicated.
- Fixed a lot of instances where the length of the argument to
append is known or easily obtain but was not used.
- Removed some not needed 'virtual' definition for functions that was
inherited from the parent. I added override to these.
- Fixed Ordered_key::print() to preallocate needed buffer. Old code could
case memory overruns.
- Simplified some loops when adding char * to a String with delimiters.
2020-08-12 19:29:55 +02:00
|
|
|
share->select_query.length= query.length();
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
share->mem_root= mem_root;
|
|
|
|
|
|
|
|
DBUG_PRINT("info",
|
Reduce usage of strlen()
Changes:
- To detect automatic strlen() I removed the methods in String that
uses 'const char *' without a length:
- String::append(const char*)
- Binary_string(const char *str)
- String(const char *str, CHARSET_INFO *cs)
- append_for_single_quote(const char *)
All usage of append(const char*) is changed to either use
String::append(char), String::append(const char*, size_t length) or
String::append(LEX_CSTRING)
- Added STRING_WITH_LEN() around constant string arguments to
String::append()
- Added overflow argument to escape_string_for_mysql() and
escape_quotes_for_mysql() instead of returning (size_t) -1 on overflow.
This was needed as most usage of the above functions never tested the
result for -1 and would have given wrong results or crashes in case
of overflows.
- Added Item_func_or_sum::func_name_cstring(), which returns LEX_CSTRING.
Changed all Item_func::func_name()'s to func_name_cstring()'s.
The old Item_func_or_sum::func_name() is now an inline function that
returns func_name_cstring().str.
- Changed Item::mode_name() and Item::func_name_ext() to return
LEX_CSTRING.
- Changed for some functions the name argument from const char * to
to const LEX_CSTRING &:
- Item::Item_func_fix_attributes()
- Item::check_type_...()
- Type_std_attributes::agg_item_collations()
- Type_std_attributes::agg_item_set_converter()
- Type_std_attributes::agg_arg_charsets...()
- Type_handler_hybrid_field_type::aggregate_for_result()
- Type_handler_geometry::check_type_geom_or_binary()
- Type_handler::Item_func_or_sum_illegal_param()
- Predicant_to_list_comparator::add_value_skip_null()
- Predicant_to_list_comparator::add_value()
- cmp_item_row::prepare_comparators()
- cmp_item_row::aggregate_row_elements_for_comparison()
- Cursor_ref::print_func()
- Removes String_space() as it was only used in one cases and that
could be simplified to not use String_space(), thanks to the fixed
my_vsnprintf().
- Added some const LEX_CSTRING's for common strings:
- NULL_clex_str, DATA_clex_str, INDEX_clex_str.
- Changed primary_key_name to a LEX_CSTRING
- Renamed String::set_quick() to String::set_buffer_if_not_allocated() to
clarify what the function really does.
- Rename of protocol function:
bool store(const char *from, CHARSET_INFO *cs) to
bool store_string_or_null(const char *from, CHARSET_INFO *cs).
This was done to both clarify the difference between this 'store' function
and also to make it easier to find unoptimal usage of store() calls.
- Added Protocol::store(const LEX_CSTRING*, CHARSET_INFO*)
- Changed some 'const char*' arrays to instead be of type LEX_CSTRING.
- class Item_func_units now used LEX_CSTRING for name.
Other things:
- Fixed a bug in mysql.cc:construct_prompt() where a wrong escape character
in the prompt would cause some part of the prompt to be duplicated.
- Fixed a lot of instances where the length of the argument to
append is known or easily obtain but was not used.
- Removed some not needed 'virtual' definition for functions that was
inherited from the parent. I added override to these.
- Fixed Ordered_key::print() to preallocate needed buffer. Old code could
case memory overruns.
- Simplified some loops when adding char * to a String with delimiters.
2020-08-12 19:29:55 +02:00
|
|
|
("share->select_query %s", share->select_query.str));
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
if (!(share->s= get_server(share, table)))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (my_hash_insert(&federatedx_open_tables, (uchar*) share))
|
|
|
|
goto error;
|
|
|
|
thr_lock_init(&share->lock);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
free_root(&mem_root, MYF(0)); /* prevents memory leak */
|
|
|
|
|
|
|
|
share->use_count++;
|
2011-07-13 21:10:18 +02:00
|
|
|
mysql_mutex_unlock(&federatedx_mutex);
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
DBUG_RETURN(share);
|
|
|
|
|
|
|
|
error:
|
2011-07-13 21:10:18 +02:00
|
|
|
mysql_mutex_unlock(&federatedx_mutex);
|
2009-10-30 19:50:56 +01:00
|
|
|
free_root(&mem_root, MYF(0));
|
|
|
|
DBUG_RETURN(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-06 01:40:51 +01:00
|
|
|
static federatedx_txn zero_txn;
|
2009-10-30 19:50:56 +01:00
|
|
|
static int free_server(federatedx_txn *txn, FEDERATEDX_SERVER *server)
|
|
|
|
{
|
|
|
|
bool destroy;
|
|
|
|
DBUG_ENTER("free_server");
|
|
|
|
|
2011-07-13 21:10:18 +02:00
|
|
|
mysql_mutex_lock(&federatedx_mutex);
|
2009-10-30 19:50:56 +01:00
|
|
|
if ((destroy= !--server->use_count))
|
2011-04-25 17:22:25 +02:00
|
|
|
my_hash_delete(&federatedx_open_servers, (uchar*) server);
|
2011-07-13 21:10:18 +02:00
|
|
|
mysql_mutex_unlock(&federatedx_mutex);
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
if (destroy)
|
|
|
|
{
|
|
|
|
MEM_ROOT mem_root;
|
|
|
|
|
2009-11-04 12:11:04 +01:00
|
|
|
if (!txn)
|
2015-12-06 01:40:51 +01:00
|
|
|
txn= &zero_txn;
|
|
|
|
|
|
|
|
txn->close(server);
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
DBUG_ASSERT(server->io_count == 0);
|
|
|
|
|
2011-07-13 21:10:18 +02:00
|
|
|
mysql_mutex_destroy(&server->mutex);
|
2009-10-30 19:50:56 +01:00
|
|
|
mem_root= server->mem_root;
|
|
|
|
free_root(&mem_root, MYF(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Free lock controls. We call this whenever we close a table.
|
|
|
|
If the table had the last reference to the share then we
|
|
|
|
free memory associated with it.
|
|
|
|
*/
|
|
|
|
|
2015-12-06 01:40:51 +01:00
|
|
|
static void free_share(federatedx_txn *txn, FEDERATEDX_SHARE *share)
|
2009-10-30 19:50:56 +01:00
|
|
|
{
|
|
|
|
bool destroy;
|
|
|
|
DBUG_ENTER("free_share");
|
|
|
|
|
2011-07-13 21:10:18 +02:00
|
|
|
mysql_mutex_lock(&federatedx_mutex);
|
2009-10-30 19:50:56 +01:00
|
|
|
if ((destroy= !--share->use_count))
|
2011-04-25 17:22:25 +02:00
|
|
|
my_hash_delete(&federatedx_open_tables, (uchar*) share);
|
2011-07-13 21:10:18 +02:00
|
|
|
mysql_mutex_unlock(&federatedx_mutex);
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
if (destroy)
|
|
|
|
{
|
|
|
|
MEM_ROOT mem_root;
|
|
|
|
FEDERATEDX_SERVER *server= share->s;
|
|
|
|
|
|
|
|
thr_lock_delete(&share->lock);
|
|
|
|
|
|
|
|
mem_root= share->mem_root;
|
|
|
|
free_root(&mem_root, MYF(0));
|
|
|
|
|
|
|
|
free_server(txn, server);
|
|
|
|
}
|
|
|
|
|
2015-12-06 01:40:51 +01:00
|
|
|
DBUG_VOID_RETURN;
|
2009-10-30 19:50:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-27 18:12:27 +01:00
|
|
|
ha_rows ha_federatedx::records_in_range(uint inx,
|
|
|
|
const key_range *start_key,
|
|
|
|
const key_range *end_key,
|
|
|
|
page_range *pages)
|
2009-10-30 19:50:56 +01:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
|
|
|
|
We really want indexes to be used as often as possible, therefore
|
|
|
|
we just need to hard-code the return value to a very low number to
|
|
|
|
force the issue
|
|
|
|
|
|
|
|
*/
|
|
|
|
DBUG_ENTER("ha_federatedx::records_in_range");
|
|
|
|
DBUG_RETURN(FEDERATEDX_RECORDS_IN_RANGE);
|
|
|
|
}
|
|
|
|
|
|
|
|
federatedx_txn *ha_federatedx::get_txn(THD *thd, bool no_create)
|
|
|
|
{
|
2019-05-16 12:19:05 +02:00
|
|
|
federatedx_txn *txn= (federatedx_txn *) thd_get_ha_data(thd, federatedx_hton);
|
|
|
|
if (!txn && !no_create)
|
|
|
|
{
|
|
|
|
txn= new federatedx_txn();
|
|
|
|
thd_set_ha_data(thd, federatedx_hton, txn);
|
|
|
|
}
|
|
|
|
return txn;
|
2009-10-30 19:50:56 +01:00
|
|
|
}
|
|
|
|
|
2010-08-12 19:52:52 +02:00
|
|
|
|
2024-09-11 19:32:38 +02:00
|
|
|
int ha_federatedx::disconnect(MYSQL_THD thd)
|
2009-10-30 19:50:56 +01:00
|
|
|
{
|
2024-09-11 19:32:38 +02:00
|
|
|
federatedx_txn *txn= (federatedx_txn *) thd_get_ha_data(thd, federatedx_hton);
|
2009-10-30 19:50:56 +01:00
|
|
|
delete txn;
|
|
|
|
return 0;
|
|
|
|
}
|
2010-08-12 19:52:52 +02:00
|
|
|
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Used for opening tables. The name will be the name of the file.
|
|
|
|
A table is opened when it needs to be opened. For instance
|
|
|
|
when a request comes in for a select on the table (tables are not
|
|
|
|
open and closed for each request, they are cached).
|
|
|
|
|
|
|
|
Called from handler.cc by handler::ha_open(). The server opens
|
|
|
|
all tables by calling ha_open() which then calls the handler
|
|
|
|
specific open().
|
|
|
|
*/
|
|
|
|
|
|
|
|
int ha_federatedx::open(const char *name, int mode, uint test_if_locked)
|
|
|
|
{
|
|
|
|
int error;
|
2015-12-06 01:40:51 +01:00
|
|
|
THD *thd= ha_thd();
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_ENTER("ha_federatedx::open");
|
|
|
|
|
|
|
|
if (!(share= get_share(name, table)))
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
thr_lock_data_init(&share->lock, &lock, NULL);
|
|
|
|
|
|
|
|
DBUG_ASSERT(io == NULL);
|
|
|
|
|
|
|
|
txn= get_txn(thd);
|
|
|
|
|
2017-08-08 19:47:34 +02:00
|
|
|
if ((error= txn->acquire(share, thd, TRUE, &io)))
|
2009-10-30 19:50:56 +01:00
|
|
|
{
|
|
|
|
free_share(txn, share);
|
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
2010-08-12 19:52:52 +02:00
|
|
|
|
2018-02-06 13:55:58 +01:00
|
|
|
ref_length= (uint)io->get_ref_length();
|
2010-08-12 19:52:52 +02:00
|
|
|
|
2009-10-30 19:50:56 +01:00
|
|
|
txn->release(&io);
|
2010-08-12 19:52:52 +02:00
|
|
|
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_PRINT("info", ("ref_length: %u", ref_length));
|
|
|
|
|
2020-02-27 11:52:20 +01:00
|
|
|
my_init_dynamic_array(PSI_INSTRUMENT_ME, &results, sizeof(FEDERATEDX_IO_RESULT*), 4, 4, MYF(0));
|
2010-08-12 19:52:52 +02:00
|
|
|
|
2009-10-30 19:50:56 +01:00
|
|
|
reset();
|
|
|
|
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2015-12-06 01:48:07 +01:00
|
|
|
class Net_error_handler : public Internal_error_handler
|
|
|
|
{
|
|
|
|
public:
|
2023-02-07 12:57:20 +01:00
|
|
|
Net_error_handler() = default;
|
2015-12-06 01:48:07 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
bool handle_condition(THD *thd, uint sql_errno, const char* sqlstate,
|
2017-01-10 17:28:24 +01:00
|
|
|
Sql_condition::enum_warning_level *level,
|
2024-06-12 15:46:26 +02:00
|
|
|
const char* msg, Sql_condition ** cond_hdl) override
|
2015-12-06 01:48:07 +01:00
|
|
|
{
|
|
|
|
return sql_errno >= ER_ABORTING_CONNECTION &&
|
|
|
|
sql_errno <= ER_NET_WRITE_INTERRUPTED;
|
|
|
|
}
|
|
|
|
};
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Closes a table. We call the free_share() function to free any resources
|
|
|
|
that we have allocated in the "shared" structure.
|
|
|
|
|
|
|
|
Called from sql_base.cc, sql_select.cc, and table.cc.
|
|
|
|
In sql_select.cc it is only used to close up temporary tables or during
|
|
|
|
the process where a temporary table is converted over to being a
|
|
|
|
myisam table.
|
|
|
|
For sql_base.cc look at close_data_tables().
|
|
|
|
*/
|
|
|
|
|
|
|
|
int ha_federatedx::close(void)
|
|
|
|
{
|
2015-12-06 01:40:51 +01:00
|
|
|
int retval= 0;
|
|
|
|
THD *thd= ha_thd();
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_ENTER("ha_federatedx::close");
|
|
|
|
|
|
|
|
/* free the result set */
|
2010-08-12 19:52:52 +02:00
|
|
|
reset();
|
2009-10-30 19:50:56 +01:00
|
|
|
|
2010-08-20 09:29:26 +02:00
|
|
|
delete_dynamic(&results);
|
2009-10-30 19:50:56 +01:00
|
|
|
|
2009-10-30 00:05:51 +01:00
|
|
|
/* Disconnect from mysql */
|
2009-12-03 12:19:05 +01:00
|
|
|
if (!thd || !(txn= get_txn(thd, true)))
|
2015-12-06 01:40:51 +01:00
|
|
|
txn= &zero_txn;
|
2009-11-14 21:15:39 +01:00
|
|
|
|
2015-12-06 01:40:51 +01:00
|
|
|
txn->release(&io);
|
|
|
|
DBUG_ASSERT(io == NULL);
|
2009-11-16 21:49:51 +01:00
|
|
|
|
2015-12-06 01:48:07 +01:00
|
|
|
Net_error_handler err_handler;
|
|
|
|
if (thd)
|
|
|
|
thd->push_internal_handler(&err_handler);
|
2015-12-06 01:40:51 +01:00
|
|
|
free_share(txn, share);
|
2015-12-06 01:48:07 +01:00
|
|
|
if (thd)
|
|
|
|
thd->pop_internal_handler();
|
2010-08-12 19:52:52 +02:00
|
|
|
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_RETURN(retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
Checks if a field in a record is SQL NULL.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
field_in_record_is_null()
|
|
|
|
table TABLE pointer, MySQL table object
|
|
|
|
field Field pointer, MySQL field object
|
|
|
|
record char pointer, contains record
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
This method uses the record format information in table to track
|
|
|
|
the null bit in record.
|
|
|
|
|
|
|
|
RETURN VALUE
|
|
|
|
1 if NULL
|
|
|
|
0 otherwise
|
|
|
|
*/
|
|
|
|
|
2015-12-06 01:40:51 +01:00
|
|
|
static inline uint field_in_record_is_null(TABLE *table, Field *field,
|
|
|
|
char *record)
|
2009-10-30 19:50:56 +01:00
|
|
|
{
|
|
|
|
int null_offset;
|
|
|
|
DBUG_ENTER("ha_federatedx::field_in_record_is_null");
|
|
|
|
|
|
|
|
if (!field->null_ptr)
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
|
|
|
|
null_offset= (uint) ((char*)field->null_ptr - (char*)table->record[0]);
|
|
|
|
|
|
|
|
if (record[null_offset] & field->null_bit)
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@brief Construct the INSERT statement.
|
|
|
|
|
|
|
|
@details This method will construct the INSERT statement and appends it to
|
|
|
|
the supplied query string buffer.
|
|
|
|
|
|
|
|
@return
|
|
|
|
@retval FALSE No error
|
|
|
|
@retval TRUE Failure
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool ha_federatedx::append_stmt_insert(String *query)
|
|
|
|
{
|
|
|
|
char insert_buffer[FEDERATEDX_QUERY_BUFFER_SIZE];
|
|
|
|
Field **field;
|
|
|
|
uint tmp_length;
|
|
|
|
bool added_field= FALSE;
|
|
|
|
|
|
|
|
/* The main insert query string */
|
|
|
|
String insert_string(insert_buffer, sizeof(insert_buffer), &my_charset_bin);
|
|
|
|
DBUG_ENTER("ha_federatedx::append_stmt_insert");
|
|
|
|
|
|
|
|
insert_string.length(0);
|
|
|
|
|
|
|
|
if (replace_duplicates)
|
|
|
|
insert_string.append(STRING_WITH_LEN("REPLACE INTO "));
|
|
|
|
else if (ignore_duplicates && !insert_dup_update)
|
|
|
|
insert_string.append(STRING_WITH_LEN("INSERT IGNORE INTO "));
|
|
|
|
else
|
|
|
|
insert_string.append(STRING_WITH_LEN("INSERT INTO "));
|
2017-04-23 18:39:57 +02:00
|
|
|
append_ident(&insert_string, share->table_name, share->table_name_length,
|
2009-10-30 19:50:56 +01:00
|
|
|
ident_quote_char);
|
|
|
|
tmp_length= insert_string.length();
|
|
|
|
insert_string.append(STRING_WITH_LEN(" ("));
|
|
|
|
|
|
|
|
/*
|
|
|
|
loop through the field pointer array, add any fields to both the values
|
|
|
|
list and the fields list that match the current query id
|
|
|
|
*/
|
|
|
|
for (field= table->field; *field; field++)
|
|
|
|
{
|
|
|
|
if (bitmap_is_set(table->write_set, (*field)->field_index))
|
|
|
|
{
|
|
|
|
/* append the field name */
|
2017-04-23 18:39:57 +02:00
|
|
|
append_ident(&insert_string, (*field)->field_name.str,
|
|
|
|
(*field)->field_name.length, ident_quote_char);
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
/* append commas between both fields and fieldnames */
|
|
|
|
/*
|
|
|
|
unfortunately, we can't use the logic if *(fields + 1) to
|
|
|
|
make the following appends conditional as we don't know if the
|
|
|
|
next field is in the write set
|
|
|
|
*/
|
|
|
|
insert_string.append(STRING_WITH_LEN(", "));
|
|
|
|
added_field= TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (added_field)
|
|
|
|
{
|
|
|
|
/* Remove trailing comma. */
|
|
|
|
insert_string.length(insert_string.length() - sizeof_trailing_comma);
|
|
|
|
insert_string.append(STRING_WITH_LEN(") "));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* If there were no fields, we don't want to add a closing paren. */
|
|
|
|
insert_string.length(tmp_length);
|
|
|
|
}
|
|
|
|
|
|
|
|
insert_string.append(STRING_WITH_LEN(" VALUES "));
|
|
|
|
|
|
|
|
DBUG_RETURN(query->append(insert_string));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
write_row() inserts a row. No extra() hint is given currently if a bulk load
|
|
|
|
is happeneding. buf() is a byte array of data. You can use the field
|
|
|
|
information to extract the data from the native byte array type.
|
|
|
|
Example of this would be:
|
|
|
|
for (Field **field=table->field ; *field ; field++)
|
|
|
|
{
|
|
|
|
...
|
|
|
|
}
|
|
|
|
|
|
|
|
Called from item_sum.cc, item_sum.cc, sql_acl.cc, sql_insert.cc,
|
|
|
|
sql_insert.cc, sql_select.cc, sql_table.cc, sql_udf.cc, and sql_update.cc.
|
|
|
|
*/
|
|
|
|
|
2019-07-04 20:31:35 +02:00
|
|
|
int ha_federatedx::write_row(const uchar *buf)
|
2009-10-30 19:50:56 +01:00
|
|
|
{
|
|
|
|
char values_buffer[FEDERATEDX_QUERY_BUFFER_SIZE];
|
|
|
|
char insert_field_value_buffer[STRING_BUFFER_USUAL_SIZE];
|
|
|
|
Field **field;
|
|
|
|
uint tmp_length;
|
|
|
|
int error= 0;
|
|
|
|
bool use_bulk_insert;
|
|
|
|
bool auto_increment_update_required= (table->next_number_field != NULL);
|
|
|
|
|
|
|
|
/* The string containing the values to be added to the insert */
|
|
|
|
String values_string(values_buffer, sizeof(values_buffer), &my_charset_bin);
|
|
|
|
/* The actual value of the field, to be added to the values_string */
|
|
|
|
String insert_field_value_string(insert_field_value_buffer,
|
|
|
|
sizeof(insert_field_value_buffer),
|
|
|
|
&my_charset_bin);
|
2018-05-14 10:47:13 +02:00
|
|
|
Time_zone *saved_time_zone= table->in_use->variables.time_zone;
|
MDEV-17556 Assertion `bitmap_is_set_all(&table->s->all_set)' failed
The assertion failed in handler::ha_reset upon SELECT under
READ UNCOMMITTED from table with index on virtual column.
This was the debug-only failure, though the problem is mush wider:
* MY_BITMAP is a structure containing my_bitmap_map, the latter is a raw
bitmap.
* read_set, write_set and vcol_set of TABLE are the pointers to MY_BITMAP
* The rest of MY_BITMAPs are stored in TABLE and TABLE_SHARE
* The pointers to the stored MY_BITMAPs, like orig_read_set etc, and
sometimes all_set and tmp_set, are assigned to the pointers.
* Sometimes tmp_use_all_columns is used to substitute the raw bitmap
directly with all_set.bitmap
* Sometimes even bitmaps are directly modified, like in
TABLE::update_virtual_field(): bitmap_clear_all(&tmp_set) is called.
The last three bullets in the list, when used together (which is mostly
always) make the program flow cumbersome and impossible to follow,
notwithstanding the errors they cause, like this MDEV-17556, where tmp_set
pointer was assigned to read_set, write_set and vcol_set, then its bitmap
was substituted with all_set.bitmap by dbug_tmp_use_all_columns() call,
and then bitmap_clear_all(&tmp_set) was applied to all this.
To untangle this knot, the rule should be applied:
* Never substitute bitmaps! This patch is about this.
orig_*, all_set bitmaps are never substituted already.
This patch changes the following function prototypes:
* tmp_use_all_columns, dbug_tmp_use_all_columns
to accept MY_BITMAP** and to return MY_BITMAP * instead of my_bitmap_map*
* tmp_restore_column_map, dbug_tmp_restore_column_maps to accept
MY_BITMAP* instead of my_bitmap_map*
These functions now will substitute read_set/write_set/vcol_set directly,
and won't touch underlying bitmaps.
2020-12-29 04:38:16 +01:00
|
|
|
MY_BITMAP *old_map= dbug_tmp_use_all_columns(table, &table->read_set);
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_ENTER("ha_federatedx::write_row");
|
|
|
|
|
2018-05-14 10:47:13 +02:00
|
|
|
table->in_use->variables.time_zone= UTC;
|
2009-10-30 19:50:56 +01:00
|
|
|
values_string.length(0);
|
|
|
|
insert_field_value_string.length(0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
start both our field and field values strings
|
|
|
|
We must disable multi-row insert for "INSERT...ON DUPLICATE KEY UPDATE"
|
|
|
|
Ignore duplicates is always true when insert_dup_update is true.
|
|
|
|
When replace_duplicates == TRUE, we can safely enable multi-row insert.
|
|
|
|
When performing multi-row insert, we only collect the columns values for
|
|
|
|
the row. The start of the statement is only created when the first
|
|
|
|
row is copied in to the bulk_insert string.
|
|
|
|
*/
|
|
|
|
if (!(use_bulk_insert= bulk_insert.str &&
|
|
|
|
(!insert_dup_update || replace_duplicates)))
|
|
|
|
append_stmt_insert(&values_string);
|
|
|
|
|
|
|
|
values_string.append(STRING_WITH_LEN(" ("));
|
|
|
|
tmp_length= values_string.length();
|
|
|
|
|
|
|
|
/*
|
|
|
|
loop through the field pointer array, add any fields to both the values
|
|
|
|
list and the fields list that is part of the write set
|
|
|
|
*/
|
|
|
|
for (field= table->field; *field; field++)
|
|
|
|
{
|
|
|
|
if (bitmap_is_set(table->write_set, (*field)->field_index))
|
|
|
|
{
|
|
|
|
if ((*field)->is_null())
|
|
|
|
values_string.append(STRING_WITH_LEN(" NULL "));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bool needs_quote= (*field)->str_needs_quotes();
|
|
|
|
(*field)->val_str(&insert_field_value_string);
|
|
|
|
if (needs_quote)
|
|
|
|
values_string.append(value_quote_char);
|
|
|
|
insert_field_value_string.print(&values_string);
|
|
|
|
if (needs_quote)
|
|
|
|
values_string.append(value_quote_char);
|
|
|
|
|
|
|
|
insert_field_value_string.length(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* append commas between both fields and fieldnames */
|
|
|
|
/*
|
|
|
|
unfortunately, we can't use the logic if *(fields + 1) to
|
|
|
|
make the following appends conditional as we don't know if the
|
|
|
|
next field is in the write set
|
|
|
|
*/
|
|
|
|
values_string.append(STRING_WITH_LEN(", "));
|
|
|
|
}
|
|
|
|
}
|
MDEV-17556 Assertion `bitmap_is_set_all(&table->s->all_set)' failed
The assertion failed in handler::ha_reset upon SELECT under
READ UNCOMMITTED from table with index on virtual column.
This was the debug-only failure, though the problem is mush wider:
* MY_BITMAP is a structure containing my_bitmap_map, the latter is a raw
bitmap.
* read_set, write_set and vcol_set of TABLE are the pointers to MY_BITMAP
* The rest of MY_BITMAPs are stored in TABLE and TABLE_SHARE
* The pointers to the stored MY_BITMAPs, like orig_read_set etc, and
sometimes all_set and tmp_set, are assigned to the pointers.
* Sometimes tmp_use_all_columns is used to substitute the raw bitmap
directly with all_set.bitmap
* Sometimes even bitmaps are directly modified, like in
TABLE::update_virtual_field(): bitmap_clear_all(&tmp_set) is called.
The last three bullets in the list, when used together (which is mostly
always) make the program flow cumbersome and impossible to follow,
notwithstanding the errors they cause, like this MDEV-17556, where tmp_set
pointer was assigned to read_set, write_set and vcol_set, then its bitmap
was substituted with all_set.bitmap by dbug_tmp_use_all_columns() call,
and then bitmap_clear_all(&tmp_set) was applied to all this.
To untangle this knot, the rule should be applied:
* Never substitute bitmaps! This patch is about this.
orig_*, all_set bitmaps are never substituted already.
This patch changes the following function prototypes:
* tmp_use_all_columns, dbug_tmp_use_all_columns
to accept MY_BITMAP** and to return MY_BITMAP * instead of my_bitmap_map*
* tmp_restore_column_map, dbug_tmp_restore_column_maps to accept
MY_BITMAP* instead of my_bitmap_map*
These functions now will substitute read_set/write_set/vcol_set directly,
and won't touch underlying bitmaps.
2020-12-29 04:38:16 +01:00
|
|
|
dbug_tmp_restore_column_map(&table->read_set, old_map);
|
2018-05-14 10:47:13 +02:00
|
|
|
table->in_use->variables.time_zone= saved_time_zone;
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
if there were no fields, we don't want to add a closing paren
|
|
|
|
AND, we don't want to chop off the last char '('
|
|
|
|
insert will be "INSERT INTO t1 VALUES ();"
|
|
|
|
*/
|
|
|
|
if (values_string.length() > tmp_length)
|
|
|
|
{
|
|
|
|
/* chops off trailing comma */
|
|
|
|
values_string.length(values_string.length() - sizeof_trailing_comma);
|
|
|
|
}
|
|
|
|
/* we always want to append this, even if there aren't any fields */
|
|
|
|
values_string.append(STRING_WITH_LEN(") "));
|
|
|
|
|
2017-08-08 19:47:34 +02:00
|
|
|
if ((error= txn->acquire(share, ha_thd(), FALSE, &io)))
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_RETURN(error);
|
|
|
|
|
|
|
|
if (use_bulk_insert)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Send the current bulk insert out if appending the current row would
|
|
|
|
cause the statement to overflow the packet size, otherwise set
|
|
|
|
auto_increment_update_required to FALSE as no query was executed.
|
|
|
|
*/
|
|
|
|
if (bulk_insert.length + values_string.length() + bulk_padding >
|
|
|
|
io->max_query_size() && bulk_insert.length)
|
|
|
|
{
|
|
|
|
error= io->query(bulk_insert.str, bulk_insert.length);
|
|
|
|
bulk_insert.length= 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
auto_increment_update_required= FALSE;
|
|
|
|
|
|
|
|
if (bulk_insert.length == 0)
|
|
|
|
{
|
|
|
|
char insert_buffer[FEDERATEDX_QUERY_BUFFER_SIZE];
|
|
|
|
String insert_string(insert_buffer, sizeof(insert_buffer),
|
|
|
|
&my_charset_bin);
|
|
|
|
insert_string.length(0);
|
|
|
|
append_stmt_insert(&insert_string);
|
|
|
|
dynstr_append_mem(&bulk_insert, insert_string.ptr(),
|
|
|
|
insert_string.length());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
dynstr_append_mem(&bulk_insert, ",", 1);
|
|
|
|
|
|
|
|
dynstr_append_mem(&bulk_insert, values_string.ptr(),
|
|
|
|
values_string.length());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error= io->query(values_string.ptr(), values_string.length());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
DBUG_RETURN(stash_remote_error());
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
If the table we've just written a record to contains an auto_increment
|
|
|
|
field, then store the last_insert_id() value from the foreign server
|
|
|
|
*/
|
|
|
|
if (auto_increment_update_required)
|
|
|
|
{
|
|
|
|
update_auto_increment();
|
|
|
|
|
|
|
|
/* mysql_insert() uses this for protocol return value */
|
|
|
|
table->next_number_field->store(stats.auto_increment_value, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@brief Prepares the storage engine for bulk inserts.
|
|
|
|
|
|
|
|
@param[in] rows estimated number of rows in bulk insert
|
|
|
|
or 0 if unknown.
|
|
|
|
|
|
|
|
@details Initializes memory structures required for bulk insert.
|
|
|
|
*/
|
|
|
|
|
2013-01-23 16:24:04 +01:00
|
|
|
void ha_federatedx::start_bulk_insert(ha_rows rows, uint flags)
|
2009-10-30 19:50:56 +01:00
|
|
|
{
|
|
|
|
uint page_size;
|
|
|
|
DBUG_ENTER("ha_federatedx::start_bulk_insert");
|
|
|
|
|
|
|
|
dynstr_free(&bulk_insert);
|
|
|
|
|
|
|
|
/**
|
|
|
|
We don't bother with bulk-insert semantics when the estimated rows == 1
|
|
|
|
The rows value will be 0 if the server does not know how many rows
|
|
|
|
would be inserted. This can occur when performing INSERT...SELECT
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (rows == 1)
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
|
|
|
|
/*
|
|
|
|
Make sure we have an open connection so that we know the
|
|
|
|
maximum packet size.
|
|
|
|
*/
|
2017-08-08 19:47:34 +02:00
|
|
|
if (txn->acquire(share, ha_thd(), FALSE, &io))
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
|
|
|
|
page_size= (uint) my_getpagesize();
|
|
|
|
|
|
|
|
if (init_dynamic_string(&bulk_insert, NULL, page_size, page_size))
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
|
|
|
|
bulk_insert.length= 0;
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@brief End bulk insert.
|
|
|
|
|
|
|
|
@details This method will send any remaining rows to the remote server.
|
|
|
|
Finally, it will deinitialize the bulk insert data structure.
|
|
|
|
|
|
|
|
@return Operation status
|
|
|
|
@retval 0 No error
|
2016-03-04 01:09:37 +01:00
|
|
|
@retval != 0 Error occurred at remote server. Also sets my_errno.
|
2009-10-30 19:50:56 +01:00
|
|
|
*/
|
|
|
|
|
2010-07-23 22:37:21 +02:00
|
|
|
int ha_federatedx::end_bulk_insert()
|
2009-10-30 19:50:56 +01:00
|
|
|
{
|
|
|
|
int error= 0;
|
|
|
|
DBUG_ENTER("ha_federatedx::end_bulk_insert");
|
|
|
|
|
2010-07-23 22:37:21 +02:00
|
|
|
if (bulk_insert.str && bulk_insert.length && !table_will_be_deleted)
|
2009-10-30 19:50:56 +01:00
|
|
|
{
|
2017-08-08 19:47:34 +02:00
|
|
|
if ((error= txn->acquire(share, ha_thd(), FALSE, &io)))
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_RETURN(error);
|
|
|
|
if (io->query(bulk_insert.str, bulk_insert.length))
|
|
|
|
error= stash_remote_error();
|
|
|
|
else
|
|
|
|
if (table->next_number_field)
|
|
|
|
update_auto_increment();
|
|
|
|
}
|
|
|
|
|
|
|
|
dynstr_free(&bulk_insert);
|
|
|
|
|
|
|
|
DBUG_RETURN(my_errno= error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
ha_federatedx::update_auto_increment
|
|
|
|
|
|
|
|
This method ensures that last_insert_id() works properly. What it simply does
|
|
|
|
is calls last_insert_id() on the foreign database immediately after insert
|
|
|
|
(if the table has an auto_increment field) and sets the insert id via
|
|
|
|
thd->insert_id(ID)).
|
|
|
|
*/
|
|
|
|
void ha_federatedx::update_auto_increment(void)
|
|
|
|
{
|
2015-12-06 01:40:51 +01:00
|
|
|
THD *thd= ha_thd();
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_ENTER("ha_federatedx::update_auto_increment");
|
|
|
|
|
|
|
|
ha_federatedx::info(HA_STATUS_AUTO);
|
|
|
|
thd->first_successful_insert_id_in_cur_stmt=
|
|
|
|
stats.auto_increment_value;
|
|
|
|
DBUG_PRINT("info",("last_insert_id: %ld", (long) stats.auto_increment_value));
|
|
|
|
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ha_federatedx::optimize(THD* thd, HA_CHECK_OPT* check_opt)
|
|
|
|
{
|
|
|
|
int error= 0;
|
|
|
|
char query_buffer[STRING_BUFFER_USUAL_SIZE];
|
|
|
|
String query(query_buffer, sizeof(query_buffer), &my_charset_bin);
|
|
|
|
DBUG_ENTER("ha_federatedx::optimize");
|
|
|
|
|
|
|
|
query.length(0);
|
|
|
|
|
|
|
|
query.set_charset(system_charset_info);
|
|
|
|
query.append(STRING_WITH_LEN("OPTIMIZE TABLE "));
|
2017-04-23 18:39:57 +02:00
|
|
|
append_ident(&query, share->table_name, share->table_name_length,
|
2009-10-30 19:50:56 +01:00
|
|
|
ident_quote_char);
|
|
|
|
|
|
|
|
DBUG_ASSERT(txn == get_txn(thd));
|
|
|
|
|
2017-08-08 19:47:34 +02:00
|
|
|
if ((error= txn->acquire(share, thd, FALSE, &io)))
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_RETURN(error);
|
|
|
|
|
|
|
|
if (io->query(query.ptr(), query.length()))
|
|
|
|
error= stash_remote_error();
|
|
|
|
|
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ha_federatedx::repair(THD* thd, HA_CHECK_OPT* check_opt)
|
|
|
|
{
|
|
|
|
int error= 0;
|
|
|
|
char query_buffer[STRING_BUFFER_USUAL_SIZE];
|
|
|
|
String query(query_buffer, sizeof(query_buffer), &my_charset_bin);
|
|
|
|
DBUG_ENTER("ha_federatedx::repair");
|
|
|
|
|
|
|
|
query.length(0);
|
|
|
|
|
|
|
|
query.set_charset(system_charset_info);
|
|
|
|
query.append(STRING_WITH_LEN("REPAIR TABLE "));
|
2017-04-23 18:39:57 +02:00
|
|
|
append_ident(&query, share->table_name, share->table_name_length,
|
2009-10-30 19:50:56 +01:00
|
|
|
ident_quote_char);
|
|
|
|
if (check_opt->flags & T_QUICK)
|
|
|
|
query.append(STRING_WITH_LEN(" QUICK"));
|
|
|
|
if (check_opt->flags & T_EXTEND)
|
|
|
|
query.append(STRING_WITH_LEN(" EXTENDED"));
|
|
|
|
if (check_opt->sql_flags & TT_USEFRM)
|
|
|
|
query.append(STRING_WITH_LEN(" USE_FRM"));
|
|
|
|
|
|
|
|
DBUG_ASSERT(txn == get_txn(thd));
|
|
|
|
|
2017-08-08 19:47:34 +02:00
|
|
|
if ((error= txn->acquire(share, thd, FALSE, &io)))
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_RETURN(error);
|
|
|
|
|
|
|
|
if (io->query(query.ptr(), query.length()))
|
|
|
|
error= stash_remote_error();
|
|
|
|
|
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Yes, update_row() does what you expect, it updates a row. old_data will have
|
|
|
|
the previous row record in it, while new_data will have the newest data in
|
|
|
|
it.
|
|
|
|
|
|
|
|
Keep in mind that the server can do updates based on ordering if an ORDER BY
|
|
|
|
clause was used. Consecutive ordering is not guaranteed.
|
|
|
|
Currently new_data will not have an updated auto_increament record, or
|
|
|
|
and updated timestamp field. You can do these for federatedx by doing these:
|
|
|
|
if (table->timestamp_on_update_now)
|
|
|
|
update_timestamp(new_row+table->timestamp_on_update_now-1);
|
|
|
|
if (table->next_number_field && record == table->record[0])
|
|
|
|
update_auto_increment();
|
|
|
|
|
|
|
|
Called from sql_select.cc, sql_acl.cc, sql_update.cc, and sql_insert.cc.
|
|
|
|
*/
|
|
|
|
|
2017-04-16 21:40:39 +02:00
|
|
|
int ha_federatedx::update_row(const uchar *old_data, const uchar *new_data)
|
2009-10-30 19:50:56 +01:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
This used to control how the query was built. If there was a
|
|
|
|
primary key, the query would be built such that there was a where
|
|
|
|
clause with only that column as the condition. This is flawed,
|
|
|
|
because if we have a multi-part primary key, it would only use the
|
|
|
|
first part! We don't need to do this anyway, because
|
|
|
|
read_range_first will retrieve the correct record, which is what
|
|
|
|
is used to build the WHERE clause. We can however use this to
|
|
|
|
append a LIMIT to the end if there is NOT a primary key. Why do
|
|
|
|
this? Because we only are updating one record, and LIMIT enforces
|
|
|
|
this.
|
|
|
|
*/
|
2014-02-19 11:05:15 +01:00
|
|
|
bool has_a_primary_key= MY_TEST(table->s->primary_key != MAX_KEY);
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
buffers for following strings
|
|
|
|
*/
|
|
|
|
char field_value_buffer[STRING_BUFFER_USUAL_SIZE];
|
|
|
|
char update_buffer[FEDERATEDX_QUERY_BUFFER_SIZE];
|
|
|
|
char where_buffer[FEDERATEDX_QUERY_BUFFER_SIZE];
|
|
|
|
|
|
|
|
/* Work area for field values */
|
|
|
|
String field_value(field_value_buffer, sizeof(field_value_buffer),
|
|
|
|
&my_charset_bin);
|
|
|
|
/* stores the update query */
|
|
|
|
String update_string(update_buffer,
|
|
|
|
sizeof(update_buffer),
|
|
|
|
&my_charset_bin);
|
|
|
|
/* stores the WHERE clause */
|
|
|
|
String where_string(where_buffer,
|
|
|
|
sizeof(where_buffer),
|
|
|
|
&my_charset_bin);
|
|
|
|
uchar *record= table->record[0];
|
|
|
|
int error;
|
|
|
|
DBUG_ENTER("ha_federatedx::update_row");
|
|
|
|
/*
|
|
|
|
set string lengths to 0 to avoid misc chars in string
|
|
|
|
*/
|
|
|
|
field_value.length(0);
|
|
|
|
update_string.length(0);
|
|
|
|
where_string.length(0);
|
|
|
|
|
|
|
|
if (ignore_duplicates)
|
|
|
|
update_string.append(STRING_WITH_LEN("UPDATE IGNORE "));
|
|
|
|
else
|
|
|
|
update_string.append(STRING_WITH_LEN("UPDATE "));
|
|
|
|
append_ident(&update_string, share->table_name,
|
|
|
|
share->table_name_length, ident_quote_char);
|
|
|
|
update_string.append(STRING_WITH_LEN(" SET "));
|
|
|
|
|
|
|
|
/*
|
|
|
|
In this loop, we want to match column names to values being inserted
|
|
|
|
(while building INSERT statement).
|
|
|
|
|
|
|
|
Iterate through table->field (new data) and share->old_field (old_data)
|
|
|
|
using the same index to create an SQL UPDATE statement. New data is
|
|
|
|
used to create SET field=value and old data is used to create WHERE
|
|
|
|
field=oldvalue
|
|
|
|
*/
|
|
|
|
|
2018-05-14 10:47:13 +02:00
|
|
|
Time_zone *saved_time_zone= table->in_use->variables.time_zone;
|
|
|
|
table->in_use->variables.time_zone= UTC;
|
2009-10-30 19:50:56 +01:00
|
|
|
for (Field **field= table->field; *field; field++)
|
|
|
|
{
|
|
|
|
if (bitmap_is_set(table->write_set, (*field)->field_index))
|
|
|
|
{
|
2017-04-23 18:39:57 +02:00
|
|
|
append_ident(&update_string, (*field)->field_name.str,
|
|
|
|
(*field)->field_name.length,
|
2009-10-30 19:50:56 +01:00
|
|
|
ident_quote_char);
|
|
|
|
update_string.append(STRING_WITH_LEN(" = "));
|
|
|
|
|
|
|
|
if ((*field)->is_null())
|
|
|
|
update_string.append(STRING_WITH_LEN(" NULL "));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* otherwise = */
|
MDEV-17556 Assertion `bitmap_is_set_all(&table->s->all_set)' failed
The assertion failed in handler::ha_reset upon SELECT under
READ UNCOMMITTED from table with index on virtual column.
This was the debug-only failure, though the problem is mush wider:
* MY_BITMAP is a structure containing my_bitmap_map, the latter is a raw
bitmap.
* read_set, write_set and vcol_set of TABLE are the pointers to MY_BITMAP
* The rest of MY_BITMAPs are stored in TABLE and TABLE_SHARE
* The pointers to the stored MY_BITMAPs, like orig_read_set etc, and
sometimes all_set and tmp_set, are assigned to the pointers.
* Sometimes tmp_use_all_columns is used to substitute the raw bitmap
directly with all_set.bitmap
* Sometimes even bitmaps are directly modified, like in
TABLE::update_virtual_field(): bitmap_clear_all(&tmp_set) is called.
The last three bullets in the list, when used together (which is mostly
always) make the program flow cumbersome and impossible to follow,
notwithstanding the errors they cause, like this MDEV-17556, where tmp_set
pointer was assigned to read_set, write_set and vcol_set, then its bitmap
was substituted with all_set.bitmap by dbug_tmp_use_all_columns() call,
and then bitmap_clear_all(&tmp_set) was applied to all this.
To untangle this knot, the rule should be applied:
* Never substitute bitmaps! This patch is about this.
orig_*, all_set bitmaps are never substituted already.
This patch changes the following function prototypes:
* tmp_use_all_columns, dbug_tmp_use_all_columns
to accept MY_BITMAP** and to return MY_BITMAP * instead of my_bitmap_map*
* tmp_restore_column_map, dbug_tmp_restore_column_maps to accept
MY_BITMAP* instead of my_bitmap_map*
These functions now will substitute read_set/write_set/vcol_set directly,
and won't touch underlying bitmaps.
2020-12-29 04:38:16 +01:00
|
|
|
MY_BITMAP *old_map= tmp_use_all_columns(table, &table->read_set);
|
2009-10-30 19:50:56 +01:00
|
|
|
bool needs_quote= (*field)->str_needs_quotes();
|
|
|
|
(*field)->val_str(&field_value);
|
|
|
|
if (needs_quote)
|
|
|
|
update_string.append(value_quote_char);
|
|
|
|
field_value.print(&update_string);
|
|
|
|
if (needs_quote)
|
|
|
|
update_string.append(value_quote_char);
|
|
|
|
field_value.length(0);
|
MDEV-17556 Assertion `bitmap_is_set_all(&table->s->all_set)' failed
The assertion failed in handler::ha_reset upon SELECT under
READ UNCOMMITTED from table with index on virtual column.
This was the debug-only failure, though the problem is mush wider:
* MY_BITMAP is a structure containing my_bitmap_map, the latter is a raw
bitmap.
* read_set, write_set and vcol_set of TABLE are the pointers to MY_BITMAP
* The rest of MY_BITMAPs are stored in TABLE and TABLE_SHARE
* The pointers to the stored MY_BITMAPs, like orig_read_set etc, and
sometimes all_set and tmp_set, are assigned to the pointers.
* Sometimes tmp_use_all_columns is used to substitute the raw bitmap
directly with all_set.bitmap
* Sometimes even bitmaps are directly modified, like in
TABLE::update_virtual_field(): bitmap_clear_all(&tmp_set) is called.
The last three bullets in the list, when used together (which is mostly
always) make the program flow cumbersome and impossible to follow,
notwithstanding the errors they cause, like this MDEV-17556, where tmp_set
pointer was assigned to read_set, write_set and vcol_set, then its bitmap
was substituted with all_set.bitmap by dbug_tmp_use_all_columns() call,
and then bitmap_clear_all(&tmp_set) was applied to all this.
To untangle this knot, the rule should be applied:
* Never substitute bitmaps! This patch is about this.
orig_*, all_set bitmaps are never substituted already.
This patch changes the following function prototypes:
* tmp_use_all_columns, dbug_tmp_use_all_columns
to accept MY_BITMAP** and to return MY_BITMAP * instead of my_bitmap_map*
* tmp_restore_column_map, dbug_tmp_restore_column_maps to accept
MY_BITMAP* instead of my_bitmap_map*
These functions now will substitute read_set/write_set/vcol_set directly,
and won't touch underlying bitmaps.
2020-12-29 04:38:16 +01:00
|
|
|
tmp_restore_column_map(&table->read_set, old_map);
|
2009-10-30 19:50:56 +01:00
|
|
|
}
|
|
|
|
update_string.append(STRING_WITH_LEN(", "));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bitmap_is_set(table->read_set, (*field)->field_index))
|
|
|
|
{
|
2017-04-23 18:39:57 +02:00
|
|
|
append_ident(&where_string, (*field)->field_name.str,
|
|
|
|
(*field)->field_name.length,
|
2009-10-30 19:50:56 +01:00
|
|
|
ident_quote_char);
|
|
|
|
if (field_in_record_is_null(table, *field, (char*) old_data))
|
|
|
|
where_string.append(STRING_WITH_LEN(" IS NULL "));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bool needs_quote= (*field)->str_needs_quotes();
|
|
|
|
where_string.append(STRING_WITH_LEN(" = "));
|
|
|
|
(*field)->val_str(&field_value,
|
|
|
|
(old_data + (*field)->offset(record)));
|
|
|
|
if (needs_quote)
|
|
|
|
where_string.append(value_quote_char);
|
|
|
|
field_value.print(&where_string);
|
|
|
|
if (needs_quote)
|
|
|
|
where_string.append(value_quote_char);
|
|
|
|
field_value.length(0);
|
|
|
|
}
|
|
|
|
where_string.append(STRING_WITH_LEN(" AND "));
|
|
|
|
}
|
|
|
|
}
|
2018-05-14 10:47:13 +02:00
|
|
|
table->in_use->variables.time_zone= saved_time_zone;
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
/* Remove last ', '. This works as there must be at least on updated field */
|
|
|
|
update_string.length(update_string.length() - sizeof_trailing_comma);
|
|
|
|
|
|
|
|
if (where_string.length())
|
|
|
|
{
|
|
|
|
/* chop off trailing AND */
|
|
|
|
where_string.length(where_string.length() - sizeof_trailing_and);
|
|
|
|
update_string.append(STRING_WITH_LEN(" WHERE "));
|
|
|
|
update_string.append(where_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
If this table has not a primary key, then we could possibly
|
|
|
|
update multiple rows. We want to make sure to only update one!
|
|
|
|
*/
|
|
|
|
if (!has_a_primary_key)
|
|
|
|
update_string.append(STRING_WITH_LEN(" LIMIT 1"));
|
|
|
|
|
2017-08-08 19:47:34 +02:00
|
|
|
if ((error= txn->acquire(share, ha_thd(), FALSE, &io)))
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_RETURN(error);
|
|
|
|
|
|
|
|
if (io->query(update_string.ptr(), update_string.length()))
|
|
|
|
{
|
|
|
|
DBUG_RETURN(stash_remote_error());
|
|
|
|
}
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
This will delete a row. 'buf' will contain a copy of the row to be =deleted.
|
|
|
|
The server will call this right after the current row has been called (from
|
|
|
|
either a previous rnd_next() or index call).
|
|
|
|
If you keep a pointer to the last row or can access a primary key it will
|
|
|
|
make doing the deletion quite a bit easier.
|
|
|
|
Keep in mind that the server does no guarentee consecutive deletions.
|
|
|
|
ORDER BY clauses can be used.
|
|
|
|
|
|
|
|
Called in sql_acl.cc and sql_udf.cc to manage internal table information.
|
|
|
|
Called in sql_delete.cc, sql_insert.cc, and sql_select.cc. In sql_select
|
|
|
|
it is used for removing duplicates while in insert it is used for REPLACE
|
|
|
|
calls.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int ha_federatedx::delete_row(const uchar *buf)
|
|
|
|
{
|
|
|
|
char delete_buffer[FEDERATEDX_QUERY_BUFFER_SIZE];
|
|
|
|
char data_buffer[FEDERATEDX_QUERY_BUFFER_SIZE];
|
|
|
|
String delete_string(delete_buffer, sizeof(delete_buffer), &my_charset_bin);
|
|
|
|
String data_string(data_buffer, sizeof(data_buffer), &my_charset_bin);
|
|
|
|
uint found= 0;
|
|
|
|
int error;
|
|
|
|
DBUG_ENTER("ha_federatedx::delete_row");
|
|
|
|
|
|
|
|
delete_string.length(0);
|
|
|
|
delete_string.append(STRING_WITH_LEN("DELETE FROM "));
|
|
|
|
append_ident(&delete_string, share->table_name,
|
|
|
|
share->table_name_length, ident_quote_char);
|
|
|
|
delete_string.append(STRING_WITH_LEN(" WHERE "));
|
|
|
|
|
2018-05-14 10:47:13 +02:00
|
|
|
Time_zone *saved_time_zone= table->in_use->variables.time_zone;
|
|
|
|
table->in_use->variables.time_zone= UTC;
|
2009-10-30 19:50:56 +01:00
|
|
|
for (Field **field= table->field; *field; field++)
|
|
|
|
{
|
|
|
|
Field *cur_field= *field;
|
|
|
|
found++;
|
|
|
|
if (bitmap_is_set(table->read_set, cur_field->field_index))
|
|
|
|
{
|
2017-04-23 18:39:57 +02:00
|
|
|
append_ident(&delete_string, (*field)->field_name.str,
|
|
|
|
(*field)->field_name.length, ident_quote_char);
|
2009-10-30 19:50:56 +01:00
|
|
|
data_string.length(0);
|
|
|
|
if (cur_field->is_null())
|
|
|
|
{
|
|
|
|
delete_string.append(STRING_WITH_LEN(" IS NULL "));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bool needs_quote= cur_field->str_needs_quotes();
|
|
|
|
delete_string.append(STRING_WITH_LEN(" = "));
|
|
|
|
cur_field->val_str(&data_string);
|
|
|
|
if (needs_quote)
|
|
|
|
delete_string.append(value_quote_char);
|
|
|
|
data_string.print(&delete_string);
|
|
|
|
if (needs_quote)
|
|
|
|
delete_string.append(value_quote_char);
|
|
|
|
}
|
|
|
|
delete_string.append(STRING_WITH_LEN(" AND "));
|
|
|
|
}
|
|
|
|
}
|
2018-05-14 10:47:13 +02:00
|
|
|
table->in_use->variables.time_zone= saved_time_zone;
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
// Remove trailing AND
|
|
|
|
delete_string.length(delete_string.length() - sizeof_trailing_and);
|
|
|
|
if (!found)
|
|
|
|
delete_string.length(delete_string.length() - sizeof_trailing_where);
|
|
|
|
|
|
|
|
delete_string.append(STRING_WITH_LEN(" LIMIT 1"));
|
|
|
|
DBUG_PRINT("info",
|
|
|
|
("Delete sql: %s", delete_string.c_ptr_quick()));
|
|
|
|
|
2017-08-08 19:47:34 +02:00
|
|
|
if ((error= txn->acquire(share, ha_thd(), FALSE, &io)))
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_RETURN(error);
|
|
|
|
|
|
|
|
if (io->query(delete_string.ptr(), delete_string.length()))
|
|
|
|
{
|
|
|
|
DBUG_RETURN(stash_remote_error());
|
|
|
|
}
|
|
|
|
stats.deleted+= (ha_rows) io->affected_rows();
|
|
|
|
stats.records-= (ha_rows) io->affected_rows();
|
|
|
|
DBUG_PRINT("info",
|
|
|
|
("rows deleted %ld rows deleted for all time %ld",
|
|
|
|
(long) io->affected_rows(), (long) stats.deleted));
|
|
|
|
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Positions an index cursor to the index specified in the handle. Fetches the
|
|
|
|
row if available. If the key value is null, begin at the first key of the
|
|
|
|
index. This method, which is called in the case of an SQL statement having
|
|
|
|
a WHERE clause on a non-primary key index, simply calls index_read_idx.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int ha_federatedx::index_read(uchar *buf, const uchar *key,
|
|
|
|
uint key_len, ha_rkey_function find_flag)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_federatedx::index_read");
|
|
|
|
|
|
|
|
if (stored_result)
|
|
|
|
(void) free_result();
|
|
|
|
DBUG_RETURN(index_read_idx_with_result_set(buf, active_index, key,
|
|
|
|
key_len, find_flag,
|
|
|
|
&stored_result));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Positions an index cursor to the index specified in key. Fetches the
|
|
|
|
row if any. This is only used to read whole keys.
|
|
|
|
|
|
|
|
This method is called via index_read in the case of a WHERE clause using
|
|
|
|
a primary key index OR is called DIRECTLY when the WHERE clause
|
|
|
|
uses a PRIMARY KEY index.
|
|
|
|
|
|
|
|
NOTES
|
|
|
|
This uses an internal result set that is deleted before function
|
|
|
|
returns. We need to be able to be callable from ha_rnd_pos()
|
|
|
|
*/
|
|
|
|
|
|
|
|
int ha_federatedx::index_read_idx(uchar *buf, uint index, const uchar *key,
|
|
|
|
uint key_len, enum ha_rkey_function find_flag)
|
|
|
|
{
|
|
|
|
int retval;
|
2010-08-12 19:52:52 +02:00
|
|
|
FEDERATEDX_IO_RESULT *io_result= 0;
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_ENTER("ha_federatedx::index_read_idx");
|
|
|
|
|
|
|
|
if ((retval= index_read_idx_with_result_set(buf, index, key,
|
|
|
|
key_len, find_flag,
|
|
|
|
&io_result)))
|
|
|
|
DBUG_RETURN(retval);
|
|
|
|
/* io is correct, as index_read_idx_with_result_set was ok */
|
|
|
|
io->free_result(io_result);
|
|
|
|
DBUG_RETURN(retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Create result set for rows matching query and return first row
|
|
|
|
|
|
|
|
RESULT
|
|
|
|
0 ok In this case *result will contain the result set
|
|
|
|
# error In this case *result will contain 0
|
|
|
|
*/
|
|
|
|
|
|
|
|
int ha_federatedx::index_read_idx_with_result_set(uchar *buf, uint index,
|
|
|
|
const uchar *key,
|
|
|
|
uint key_len,
|
|
|
|
ha_rkey_function find_flag,
|
|
|
|
FEDERATEDX_IO_RESULT **result)
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
char error_buffer[FEDERATEDX_QUERY_BUFFER_SIZE];
|
|
|
|
char index_value[STRING_BUFFER_USUAL_SIZE];
|
|
|
|
char sql_query_buffer[FEDERATEDX_QUERY_BUFFER_SIZE];
|
|
|
|
String index_string(index_value,
|
|
|
|
sizeof(index_value),
|
|
|
|
&my_charset_bin);
|
|
|
|
String sql_query(sql_query_buffer,
|
|
|
|
sizeof(sql_query_buffer),
|
|
|
|
&my_charset_bin);
|
|
|
|
key_range range;
|
|
|
|
DBUG_ENTER("ha_federatedx::index_read_idx_with_result_set");
|
|
|
|
|
|
|
|
*result= 0; // In case of errors
|
|
|
|
index_string.length(0);
|
|
|
|
sql_query.length(0);
|
|
|
|
|
|
|
|
sql_query.append(share->select_query);
|
|
|
|
|
|
|
|
range.key= key;
|
|
|
|
range.length= key_len;
|
|
|
|
range.flag= find_flag;
|
2022-01-01 16:25:48 +01:00
|
|
|
create_where_from_key(&index_string, &table->key_info[index], &range, 0, 0);
|
2009-10-30 19:50:56 +01:00
|
|
|
sql_query.append(index_string);
|
|
|
|
|
2017-08-08 19:47:34 +02:00
|
|
|
if ((retval= txn->acquire(share, ha_thd(), TRUE, &io)))
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_RETURN(retval);
|
|
|
|
|
|
|
|
if (io->query(sql_query.ptr(), sql_query.length()))
|
|
|
|
{
|
2022-09-28 16:45:25 +02:00
|
|
|
snprintf(error_buffer, sizeof(error_buffer), "error: %d '%s'",
|
2011-07-02 22:12:12 +02:00
|
|
|
io->error_code(), io->error_str());
|
2009-10-30 19:50:56 +01:00
|
|
|
retval= ER_QUERY_ON_FOREIGN_DATA_SOURCE;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (!(*result= io->store_result()))
|
|
|
|
{
|
|
|
|
retval= HA_ERR_END_OF_FILE;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (!(retval= read_next(buf, *result)))
|
|
|
|
DBUG_RETURN(retval);
|
|
|
|
|
2010-08-12 19:52:52 +02:00
|
|
|
insert_dynamic(&results, (uchar*) result);
|
2009-10-30 19:50:56 +01:00
|
|
|
*result= 0;
|
|
|
|
DBUG_RETURN(retval);
|
|
|
|
|
|
|
|
error:
|
|
|
|
my_error(retval, MYF(0), error_buffer);
|
|
|
|
DBUG_RETURN(retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
This method is used exlusevely by filesort() to check if we
|
|
|
|
can create sorting buffers of necessary size.
|
|
|
|
If the handler returns more records that it declares
|
|
|
|
here server can just crash on filesort().
|
|
|
|
We cannot guarantee that's not going to happen with
|
|
|
|
the FEDERATEDX engine, as we have records==0 always if the
|
|
|
|
client is a VIEW, and for the table the number of
|
|
|
|
records can inpredictably change during execution.
|
|
|
|
So we return maximum possible value here.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ha_rows ha_federatedx::estimate_rows_upper_bound()
|
|
|
|
{
|
|
|
|
return HA_POS_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Initialized at each key walk (called multiple times unlike rnd_init()) */
|
|
|
|
|
|
|
|
int ha_federatedx::index_init(uint keynr, bool sorted)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_federatedx::index_init");
|
|
|
|
DBUG_PRINT("info", ("table: '%s' key: %u", table->s->table_name.str, keynr));
|
|
|
|
active_index= keynr;
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Read first range
|
|
|
|
*/
|
|
|
|
|
|
|
|
int ha_federatedx::read_range_first(const key_range *start_key,
|
|
|
|
const key_range *end_key,
|
|
|
|
bool eq_range_arg, bool sorted)
|
|
|
|
{
|
|
|
|
char sql_query_buffer[FEDERATEDX_QUERY_BUFFER_SIZE];
|
|
|
|
int retval;
|
|
|
|
String sql_query(sql_query_buffer,
|
|
|
|
sizeof(sql_query_buffer),
|
|
|
|
&my_charset_bin);
|
|
|
|
DBUG_ENTER("ha_federatedx::read_range_first");
|
|
|
|
|
|
|
|
DBUG_ASSERT(!(start_key == NULL && end_key == NULL));
|
|
|
|
|
|
|
|
sql_query.length(0);
|
|
|
|
sql_query.append(share->select_query);
|
2022-01-01 16:25:48 +01:00
|
|
|
create_where_from_key(&sql_query, &table->key_info[active_index],
|
|
|
|
start_key, end_key, eq_range_arg);
|
2009-10-30 19:50:56 +01:00
|
|
|
|
2017-08-08 19:47:34 +02:00
|
|
|
if ((retval= txn->acquire(share, ha_thd(), TRUE, &io)))
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_RETURN(retval);
|
|
|
|
|
|
|
|
if (stored_result)
|
2010-08-12 19:52:52 +02:00
|
|
|
(void) free_result();
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
if (io->query(sql_query.ptr(), sql_query.length()))
|
|
|
|
{
|
|
|
|
retval= ER_QUERY_ON_FOREIGN_DATA_SOURCE;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
sql_query.length(0);
|
|
|
|
|
|
|
|
if (!(stored_result= io->store_result()))
|
|
|
|
{
|
|
|
|
retval= HA_ERR_END_OF_FILE;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
retval= read_next(table->record[0], stored_result);
|
|
|
|
DBUG_RETURN(retval);
|
|
|
|
|
|
|
|
error:
|
|
|
|
DBUG_RETURN(retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ha_federatedx::read_range_next()
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
DBUG_ENTER("ha_federatedx::read_range_next");
|
|
|
|
retval= rnd_next(table->record[0]);
|
|
|
|
DBUG_RETURN(retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Used to read forward through the index. */
|
|
|
|
int ha_federatedx::index_next(uchar *buf)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_federatedx::index_next");
|
2014-02-21 00:52:58 +01:00
|
|
|
int retval=read_next(buf, stored_result);
|
|
|
|
DBUG_RETURN(retval);
|
2009-10-30 19:50:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
rnd_init() is called when the system wants the storage engine to do a table
|
|
|
|
scan.
|
|
|
|
|
|
|
|
This is the method that gets data for the SELECT calls.
|
|
|
|
|
|
|
|
See the federatedx in the introduction at the top of this file to see when
|
|
|
|
rnd_init() is called.
|
|
|
|
|
|
|
|
Called from filesort.cc, records.cc, sql_handler.cc, sql_select.cc,
|
|
|
|
sql_table.cc, and sql_update.cc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int ha_federatedx::rnd_init(bool scan)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_federatedx::rnd_init");
|
|
|
|
/*
|
|
|
|
The use of the 'scan' flag is incredibly important for this handler
|
|
|
|
to work properly, especially with updates containing WHERE clauses
|
|
|
|
using indexed columns.
|
|
|
|
|
|
|
|
When the initial query contains a WHERE clause of the query using an
|
|
|
|
indexed column, it's index_read_idx that selects the exact record from
|
|
|
|
the foreign database.
|
|
|
|
|
|
|
|
When there is NO index in the query, either due to not having a WHERE
|
|
|
|
clause, or the WHERE clause is using columns that are not indexed, a
|
|
|
|
'full table scan' done by rnd_init, which in this situation simply means
|
|
|
|
a 'select * from ...' on the foreign table.
|
|
|
|
|
|
|
|
In other words, this 'scan' flag gives us the means to ensure that if
|
|
|
|
there is an index involved in the query, we want index_read_idx to
|
|
|
|
retrieve the exact record (scan flag is 0), and do not want rnd_init
|
|
|
|
to do a 'full table scan' and wipe out that result set.
|
|
|
|
|
|
|
|
Prior to using this flag, the problem was most apparent with updates.
|
|
|
|
|
|
|
|
An initial query like 'UPDATE tablename SET anything = whatever WHERE
|
|
|
|
indexedcol = someval', index_read_idx would get called, using a query
|
|
|
|
constructed with a WHERE clause built from the values of index ('indexcol'
|
|
|
|
in this case, having a value of 'someval'). mysql_store_result would
|
|
|
|
then get called (this would be the result set we want to use).
|
|
|
|
|
|
|
|
After this rnd_init (from sql_update.cc) would be called, it would then
|
|
|
|
unecessarily call "select * from table" on the foreign table, then call
|
|
|
|
mysql_store_result, which would wipe out the correct previous result set
|
|
|
|
from the previous call of index_read_idx's that had the result set
|
|
|
|
containing the correct record, hence update the wrong row!
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (scan)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
2017-08-08 19:47:34 +02:00
|
|
|
if ((error= txn->acquire(share, ha_thd(), TRUE, &io)))
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_RETURN(error);
|
|
|
|
|
|
|
|
if (stored_result)
|
2010-08-12 19:52:52 +02:00
|
|
|
(void) free_result();
|
2009-10-30 19:50:56 +01:00
|
|
|
|
Reduce usage of strlen()
Changes:
- To detect automatic strlen() I removed the methods in String that
uses 'const char *' without a length:
- String::append(const char*)
- Binary_string(const char *str)
- String(const char *str, CHARSET_INFO *cs)
- append_for_single_quote(const char *)
All usage of append(const char*) is changed to either use
String::append(char), String::append(const char*, size_t length) or
String::append(LEX_CSTRING)
- Added STRING_WITH_LEN() around constant string arguments to
String::append()
- Added overflow argument to escape_string_for_mysql() and
escape_quotes_for_mysql() instead of returning (size_t) -1 on overflow.
This was needed as most usage of the above functions never tested the
result for -1 and would have given wrong results or crashes in case
of overflows.
- Added Item_func_or_sum::func_name_cstring(), which returns LEX_CSTRING.
Changed all Item_func::func_name()'s to func_name_cstring()'s.
The old Item_func_or_sum::func_name() is now an inline function that
returns func_name_cstring().str.
- Changed Item::mode_name() and Item::func_name_ext() to return
LEX_CSTRING.
- Changed for some functions the name argument from const char * to
to const LEX_CSTRING &:
- Item::Item_func_fix_attributes()
- Item::check_type_...()
- Type_std_attributes::agg_item_collations()
- Type_std_attributes::agg_item_set_converter()
- Type_std_attributes::agg_arg_charsets...()
- Type_handler_hybrid_field_type::aggregate_for_result()
- Type_handler_geometry::check_type_geom_or_binary()
- Type_handler::Item_func_or_sum_illegal_param()
- Predicant_to_list_comparator::add_value_skip_null()
- Predicant_to_list_comparator::add_value()
- cmp_item_row::prepare_comparators()
- cmp_item_row::aggregate_row_elements_for_comparison()
- Cursor_ref::print_func()
- Removes String_space() as it was only used in one cases and that
could be simplified to not use String_space(), thanks to the fixed
my_vsnprintf().
- Added some const LEX_CSTRING's for common strings:
- NULL_clex_str, DATA_clex_str, INDEX_clex_str.
- Changed primary_key_name to a LEX_CSTRING
- Renamed String::set_quick() to String::set_buffer_if_not_allocated() to
clarify what the function really does.
- Rename of protocol function:
bool store(const char *from, CHARSET_INFO *cs) to
bool store_string_or_null(const char *from, CHARSET_INFO *cs).
This was done to both clarify the difference between this 'store' function
and also to make it easier to find unoptimal usage of store() calls.
- Added Protocol::store(const LEX_CSTRING*, CHARSET_INFO*)
- Changed some 'const char*' arrays to instead be of type LEX_CSTRING.
- class Item_func_units now used LEX_CSTRING for name.
Other things:
- Fixed a bug in mysql.cc:construct_prompt() where a wrong escape character
in the prompt would cause some part of the prompt to be duplicated.
- Fixed a lot of instances where the length of the argument to
append is known or easily obtain but was not used.
- Removed some not needed 'virtual' definition for functions that was
inherited from the parent. I added override to these.
- Fixed Ordered_key::print() to preallocate needed buffer. Old code could
case memory overruns.
- Simplified some loops when adding char * to a String with delimiters.
2020-08-12 19:29:55 +02:00
|
|
|
if (io->query(share->select_query.str, share->select_query.length))
|
2009-10-30 19:50:56 +01:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
stored_result= io->store_result();
|
|
|
|
if (!stored_result)
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
|
|
|
|
error:
|
|
|
|
DBUG_RETURN(stash_remote_error());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ha_federatedx::rnd_end()
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_federatedx::rnd_end");
|
|
|
|
DBUG_RETURN(index_end());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ha_federatedx::free_result()
|
|
|
|
{
|
|
|
|
int error;
|
2010-08-12 19:52:52 +02:00
|
|
|
DBUG_ENTER("ha_federatedx::free_result");
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_ASSERT(stored_result);
|
2010-08-12 19:52:52 +02:00
|
|
|
for (uint i= 0; i < results.elements; ++i)
|
2009-10-30 19:50:56 +01:00
|
|
|
{
|
2010-08-12 19:52:52 +02:00
|
|
|
FEDERATEDX_IO_RESULT *result= 0;
|
|
|
|
get_dynamic(&results, (uchar*) &result, i);
|
|
|
|
if (result == stored_result)
|
|
|
|
goto end;
|
2009-10-30 19:50:56 +01:00
|
|
|
}
|
2010-08-12 19:52:52 +02:00
|
|
|
if (position_called)
|
2009-10-30 19:50:56 +01:00
|
|
|
{
|
2010-08-12 19:52:52 +02:00
|
|
|
insert_dynamic(&results, (uchar*) &stored_result);
|
2009-10-30 19:50:56 +01:00
|
|
|
}
|
2010-08-12 19:52:52 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
federatedx_io *tmp_io= 0, **iop;
|
2017-08-08 19:47:34 +02:00
|
|
|
if (!*(iop= &io) && (error= txn->acquire(share, ha_thd(), TRUE, (iop= &tmp_io))))
|
2010-08-12 19:52:52 +02:00
|
|
|
{
|
|
|
|
DBUG_ASSERT(0); // Fail when testing
|
|
|
|
insert_dynamic(&results, (uchar*) &stored_result);
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
(*iop)->free_result(stored_result);
|
|
|
|
txn->release(&tmp_io);
|
|
|
|
}
|
|
|
|
end:
|
2009-10-30 19:50:56 +01:00
|
|
|
stored_result= 0;
|
2010-08-12 19:52:52 +02:00
|
|
|
position_called= FALSE;
|
|
|
|
DBUG_RETURN(0);
|
2009-10-30 19:50:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int ha_federatedx::index_end(void)
|
|
|
|
{
|
|
|
|
int error= 0;
|
|
|
|
DBUG_ENTER("ha_federatedx::index_end");
|
|
|
|
if (stored_result)
|
|
|
|
error= free_result();
|
|
|
|
active_index= MAX_KEY;
|
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
This is called for each row of the table scan. When you run out of records
|
|
|
|
you should return HA_ERR_END_OF_FILE. Fill buff up with the row information.
|
|
|
|
The Field structure for the table is the key to getting data into buf
|
|
|
|
in a manner that will allow the server to understand it.
|
|
|
|
|
|
|
|
Called from filesort.cc, records.cc, sql_handler.cc, sql_select.cc,
|
|
|
|
sql_table.cc, and sql_update.cc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int ha_federatedx::rnd_next(uchar *buf)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_federatedx::rnd_next");
|
|
|
|
|
|
|
|
if (stored_result == 0)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Return value of rnd_init is not always checked (see records.cc),
|
|
|
|
so we can get here _even_ if there is _no_ pre-fetched result-set!
|
|
|
|
TODO: fix it. We can delete this in 5.1 when rnd_init() is checked.
|
|
|
|
*/
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
2014-02-21 00:52:58 +01:00
|
|
|
int retval=read_next(buf, stored_result);
|
|
|
|
DBUG_RETURN(retval);
|
2009-10-30 19:50:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
ha_federatedx::read_next
|
|
|
|
|
|
|
|
reads from a result set and converts to mysql internal
|
|
|
|
format
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
field_in_record_is_null()
|
2010-08-12 19:52:52 +02:00
|
|
|
buf byte pointer to record
|
|
|
|
result mysql result set
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
This method is a wrapper method that reads one record from a result
|
|
|
|
set and converts it to the internal table format
|
|
|
|
|
|
|
|
RETURN VALUE
|
|
|
|
1 error
|
|
|
|
0 no error
|
|
|
|
*/
|
|
|
|
|
|
|
|
int ha_federatedx::read_next(uchar *buf, FEDERATEDX_IO_RESULT *result)
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
FEDERATEDX_IO_ROW *row;
|
|
|
|
DBUG_ENTER("ha_federatedx::read_next");
|
|
|
|
|
2017-08-08 19:47:34 +02:00
|
|
|
if ((retval= txn->acquire(share, ha_thd(), TRUE, &io)))
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_RETURN(retval);
|
|
|
|
|
|
|
|
/* Fetch a row, insert it back in a row format. */
|
2020-12-09 18:15:29 +01:00
|
|
|
if (!(row= io->fetch_row(result, ¤t)))
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_RETURN(HA_ERR_END_OF_FILE);
|
|
|
|
|
|
|
|
if (!(retval= convert_row_to_internal_format(buf, row, result)))
|
|
|
|
table->status= 0;
|
|
|
|
|
|
|
|
DBUG_RETURN(retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-12 19:52:52 +02:00
|
|
|
/**
|
|
|
|
@brief Store a reference to current row.
|
|
|
|
|
|
|
|
@details During a query execution we may have different result sets (RS),
|
|
|
|
e.g. for different ranges. All the RS's used are stored in
|
|
|
|
memory and placed in @c results dynamic array. At the end of
|
|
|
|
execution all stored RS's are freed at once in the
|
|
|
|
@c ha_federated::reset().
|
|
|
|
So, in case of federated, a reference to current row is a
|
|
|
|
stored result address and current data cursor position.
|
|
|
|
As we keep all RS in memory during a query execution,
|
|
|
|
we can get any record using the reference any time until
|
|
|
|
@c ha_federated::reset() is called.
|
|
|
|
TODO: we don't have to store all RS's rows but only those
|
|
|
|
we call @c ha_federated::position() for, so we can free memory
|
|
|
|
where we store other rows in the @c ha_federated::index_end().
|
|
|
|
|
|
|
|
@param[in] record record data (unused)
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2010-08-12 19:52:52 +02:00
|
|
|
void ha_federatedx::position(const uchar *record __attribute__ ((unused)))
|
2009-10-30 19:50:56 +01:00
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_federatedx::position");
|
2010-08-12 19:52:52 +02:00
|
|
|
|
|
|
|
if (!stored_result)
|
2014-02-21 00:52:58 +01:00
|
|
|
{
|
|
|
|
bzero(ref, ref_length);
|
2010-08-12 19:52:52 +02:00
|
|
|
DBUG_VOID_RETURN;
|
2014-02-21 00:52:58 +01:00
|
|
|
}
|
2010-08-12 19:52:52 +02:00
|
|
|
|
2017-08-08 19:47:34 +02:00
|
|
|
if (txn->acquire(share, ha_thd(), TRUE, &io))
|
2010-08-12 19:52:52 +02:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
|
2020-12-09 18:15:29 +01:00
|
|
|
io->mark_position(stored_result, ref, current);
|
2010-08-12 19:52:52 +02:00
|
|
|
|
|
|
|
position_called= TRUE;
|
|
|
|
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
This is like rnd_next, but you are given a position to use to determine the
|
|
|
|
row. The position will be of the type that you stored in ref.
|
|
|
|
|
|
|
|
This method is required for an ORDER BY
|
|
|
|
|
|
|
|
Called from filesort.cc records.cc sql_insert.cc sql_select.cc sql_update.cc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int ha_federatedx::rnd_pos(uchar *buf, uchar *pos)
|
|
|
|
{
|
2010-08-12 19:52:52 +02:00
|
|
|
int retval;
|
|
|
|
FEDERATEDX_IO_RESULT *result= stored_result;
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_ENTER("ha_federatedx::rnd_pos");
|
2010-08-12 19:52:52 +02:00
|
|
|
|
2010-09-03 12:01:47 +02:00
|
|
|
/* We have to move this to 'ref' to get things aligned */
|
|
|
|
bmove(ref, pos, ref_length);
|
|
|
|
|
2017-08-08 19:47:34 +02:00
|
|
|
if ((retval= txn->acquire(share, ha_thd(), TRUE, &io)))
|
2010-08-12 19:52:52 +02:00
|
|
|
goto error;
|
|
|
|
|
2010-09-03 12:01:47 +02:00
|
|
|
if ((retval= io->seek_position(&result, ref)))
|
2010-08-12 19:52:52 +02:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
retval= read_next(buf, result);
|
|
|
|
DBUG_RETURN(retval);
|
|
|
|
|
|
|
|
error:
|
|
|
|
DBUG_RETURN(retval);
|
2009-10-30 19:50:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
::info() is used to return information to the optimizer.
|
|
|
|
Currently this table handler doesn't implement most of the fields
|
|
|
|
really needed. SHOW also makes use of this data
|
|
|
|
Another note, you will probably want to have the following in your
|
|
|
|
code:
|
|
|
|
if (records < 2)
|
|
|
|
records = 2;
|
|
|
|
The reason is that the server will optimize for cases of only a single
|
|
|
|
record. If in a table scan you don't know the number of records
|
|
|
|
it will probably be better to set records to two so you can return
|
|
|
|
as many records as you need.
|
|
|
|
Along with records a few more variables you may wish to set are:
|
|
|
|
records
|
|
|
|
deleted
|
|
|
|
data_file_length
|
|
|
|
index_file_length
|
|
|
|
delete_length
|
|
|
|
check_time
|
|
|
|
Take a look at the public variables in handler.h for more information.
|
|
|
|
|
|
|
|
Called in:
|
|
|
|
filesort.cc
|
|
|
|
ha_heap.cc
|
|
|
|
item_sum.cc
|
|
|
|
opt_sum.cc
|
|
|
|
sql_delete.cc
|
|
|
|
sql_delete.cc
|
|
|
|
sql_derived.cc
|
|
|
|
sql_select.cc
|
|
|
|
sql_select.cc
|
|
|
|
sql_select.cc
|
|
|
|
sql_select.cc
|
|
|
|
sql_select.cc
|
|
|
|
sql_show.cc
|
|
|
|
sql_show.cc
|
|
|
|
sql_show.cc
|
|
|
|
sql_show.cc
|
|
|
|
sql_table.cc
|
|
|
|
sql_union.cc
|
|
|
|
sql_update.cc
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
int ha_federatedx::info(uint flag)
|
|
|
|
{
|
|
|
|
uint error_code;
|
2015-12-06 01:40:51 +01:00
|
|
|
THD *thd= ha_thd();
|
2010-08-12 19:52:52 +02:00
|
|
|
federatedx_txn *tmp_txn;
|
2009-11-04 12:11:04 +01:00
|
|
|
federatedx_io *tmp_io= 0, **iop= 0;
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_ENTER("ha_federatedx::info");
|
|
|
|
|
|
|
|
error_code= ER_QUERY_ON_FOREIGN_DATA_SOURCE;
|
|
|
|
|
2010-08-12 19:52:52 +02:00
|
|
|
// external_lock may not have been called so txn may not be set
|
|
|
|
tmp_txn= get_txn(thd);
|
|
|
|
|
2009-10-30 19:50:56 +01:00
|
|
|
/* we want not to show table status if not needed to do so */
|
|
|
|
if (flag & (HA_STATUS_VARIABLE | HA_STATUS_CONST | HA_STATUS_AUTO))
|
|
|
|
{
|
2017-08-08 19:47:34 +02:00
|
|
|
if (!*(iop= &io) && (error_code= tmp_txn->acquire(share, thd, TRUE, (iop= &tmp_io))))
|
2009-10-30 19:50:56 +01:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flag & (HA_STATUS_VARIABLE | HA_STATUS_CONST))
|
|
|
|
{
|
|
|
|
/*
|
Update row and key fetch cost models to take into account data copy costs
Before this patch, when calculating the cost of fetching and using a
row/key from the engine, we took into account the cost of finding a
row or key from the engine, but did not consistently take into account
index only accessed, clustered key or covered keys for all access
paths.
The cost of the WHERE clause (TIME_FOR_COMPARE) was not consistently
considered in best_access_path(). TIME_FOR_COMPARE was used in
calculation in other places, like greedy_search(), but was in some
cases (like scans) done an a different number of rows than was
accessed.
The cost calculation of row and index scans didn't take into account
the number of rows that where accessed, only the number of accepted
rows.
When using a filter, the cost of index_only_reads and cost of
accessing and disregarding 'filtered rows' where not taken into
account, which made filters cost less than there actually where.
To remedy the above, the following key & row fetch related costs
has been added:
- The cost of fetching and using a row is now split into different costs:
- key + Row fetch cost (as before) but multiplied with the variable
'optimizer_cache_cost' (default to 0.5). This allows the user to
tell the optimizer the likehood of finding the key and row in the
engine cache.
- ROW_COPY_COST, The cost copying a row from the engine to the
sql layer or creating a row from the join_cache to the record
buffer. Mostly affects table scan costs.
- ROW_LOOKUP_COST, the cost of fetching a row by rowid.
- KEY_COPY_COST the cost of finding the next key and copying it from
the engine to the SQL layer. This is used when we calculate the cost
index only reads. It makes index scans more expensive than before if
they cover a lot of rows. (main.index_merge_myisam)
- KEY_LOOKUP_COST, the cost of finding the first key in a range.
This replaces the old define IDX_LOOKUP_COST, but with a higher cost.
- KEY_NEXT_FIND_COST, the cost of finding the next key (and rowid).
when doing a index scan and comparing the rowid to the filter.
Before this cost was assumed to be 0.
All of the above constants/variables are now tuned to be somewhat in
proportion of executing complexity to each other. There is tuning
need for these in the future, but that can wait until the above are
made user variables as that will make tuning much easier.
To make the usage of the above easy, there are new (not virtual)
cost calclation functions in handler:
- ha_read_time(), like read_time(), but take optimizer_cache_cost into
account.
- ha_read_and_copy_time(), like ha_read_time() but take into account
ROW_COPY_TIME
- ha_read_and_compare_time(), like ha_read_and_copy_time() but take
TIME_FOR_COMPARE into account.
- ha_rnd_pos_time(). Read row with row id, taking ROW_COPY_COST
into account. This is used with filesort where we don't need
to execute the WHERE clause again.
- ha_keyread_time(), like keyread_time() but take
optimizer_cache_cost into account.
- ha_keyread_and_copy_time(), like ha_keyread_time(), but add
KEY_COPY_COST.
- ha_key_scan_time(), like key_scan_time() but take
optimizer_cache_cost nto account.
- ha_key_scan_and_compare_time(), like ha_key_scan_time(), but add
KEY_COPY_COST & TIME_FOR_COMPARE.
I also added some setup costs for doing different types of scans and
creating temporary tables (on disk and in memory). This encourages
the optimizer to not use these for simple 'a few row' lookups if
there are adequate key lookup strategies.
- TABLE_SCAN_SETUP_COST, cost of starting a table scan.
- INDEX_SCAN_SETUP_COST, cost of starting an index scan.
- HEAP_TEMPTABLE_CREATE_COST, cost of creating in memory
temporary table.
- DISK_TEMPTABLE_CREATE_COST, cost of creating an on disk temporary
table.
When calculating cost of fetching ranges, we had a cost of
IDX_LOOKUP_COST (0.125) for doing a key div for a new range. This is
now replaced with 'io_cost * KEY_LOOKUP_COST (1.0) *
optimizer_cache_cost', which matches the cost we use for 'ref' and
other key lookups. The effect is that the cost is now a bit higher
when we have many ranges for a key.
Allmost all calculation with TIME_FOR_COMPARE is now done in
best_access_path(). 'JOIN::read_time' now includes the full
cost for finding the rows in the table.
In the result files, many of the changes are now again close to what
they where before the "Update cost for hash and cached joins" commit,
as that commit didn't fix the filter cost (too complex to do
everything in one commit).
The above changes showed a lot of a lot of inconsistencies in
optimizer cost calculation. The main objective with the other changes
was to do calculation as similar (and accurate) as possible and to make
different plans more comparable.
Detailed list of changes:
- Calculate index_only_cost consistently and correctly for all scan
and ref accesses. The row fetch_cost and index_only_cost now
takes into account clustered keys, covered keys and index
only accesses.
- cost_for_index_read now returns both full cost and index_only_cost
- Fixed cost calculation of get_sweep_read_cost() to match other
similar costs. This is bases on the assumption that data is more
often stored on SSD than a hard disk.
- Replaced constant 2.0 with new define TABLE_SCAN_SETUP_COST.
- Some scan cost estimates did not take into account
TIME_FOR_COMPARE. Now all scan costs takes this into
account. (main.show_explain)
- Added session variable optimizer_cache_hit_ratio (default 50%). By
adjusting this on can reduce or increase the cost of index or direct
record lookups. The effect of the default is that key lookups is now
a bit cheaper than before. See usage of 'optimizer_cache_cost' in
handler.h.
- JOIN_TAB::scan_time() did not take into account index only scans,
which produced a wrong cost when index scan was used. Changed
JOIN_TAB:::scan_time() to take into consideration clustered and
covered keys. The values are now cached and we only have to call
this function once. Other calls are changed to use the cached
values. Function renamed to JOIN_TAB::estimate_scan_time().
- Fixed that most index cost calculations are done the same way and
more close to 'range' calculations. The cost is now lower than
before for small data sets and higher for large data sets as we take
into account how many keys are read (main.opt_trace_selectivity,
main.limit_rows_examined).
- Ensured that index_scan_cost() ==
range(scan_of_all_rows_in_table_using_one_range) +
MULTI_RANGE_READ_INFO_CONST. One effect of this is that if there
is choice of doing a full index scan and a range-index scan over
almost the whole table then index scan will be preferred (no
range-read setup cost). (innodb.innodb, main.show_explain,
main.range)
- Fixed the EQ_REF and REF takes into account clustered and covered
keys. This changes some plans to use covered or clustered indexes
as these are much cheaper. (main.subselect_mat_cost,
main.state_tables_innodb, main.limit_rows_examined)
- Rowid filter setup cost and filter compare cost now takes into
account fetching and checking the rowid (KEY_NEXT_FIND_COST).
(main.partition_pruning heap.heap_btree main.log_state)
- Added KEY_NEXT_FIND_COST to
Range_rowid_filter_cost_info::lookup_cost to account of the time
to find and check the next key value against the container
- Introduced ha_keyread_time(rows) that takes into account finding
the next row and copying the key value to 'record'
(KEY_COPY_COST).
- Introduced ha_key_scan_time() for calculating an index scan over
all rows.
- Added IDX_LOOKUP_COST to keyread_time() as a startup cost.
- Added index_only_fetch_cost() as a convenience function to
OPT_RANGE.
- keyread_time() cost is slightly reduced to prefer shorter keys.
(main.index_merge_myisam)
- All of the above caused some index_merge combinations to be
rejected because of cost (main.index_intersect). In some cases
'ref' where replaced with index_merge because of the low
cost calculation of get_sweep_read_cost().
- Some index usage moved from PRIMARY to a covering index.
(main.subselect_innodb)
- Changed cost calculation of filter to take KEY_LOOKUP_COST and
TIME_FOR_COMPARE into account. See sql_select.cc::apply_filter().
filter parameters and costs are now written to optimizer_trace.
- Don't use matchings_records_in_range() to try to estimate the number
of filtered rows for ranges. The reason is that we want to ensure
that 'range' is calculated similar to 'ref'. There is also more work
needed to calculate the selectivity when using ranges and ranges and
filtering. This causes filtering column in EXPLAIN EXTENDED to be
100.00 for some cases where range cannot use filtering.
(main.rowid_filter)
- Introduced ha_scan_time() that takes into account the CPU cost of
finding the next row and copying the row from the engine to
'record'. This causes costs of table scan to slightly increase and
some test to changed their plan from ALL to RANGE or ALL to ref.
(innodb.innodb_mysql, main.select_pkeycache)
In a few cases where scan time of very small tables have lower cost
than a ref or range, things changed from ref/range to ALL.
(main.myisam, main.func_group, main.limit_rows_examined,
main.subselect2)
- Introduced ha_scan_and_compare_time() which is like ha_scan_time()
but also adds the cost of the where clause (TIME_FOR_COMPARE).
- Added small cost for creating temporary table for
materialization. This causes some very small tables to use scan
instead of materialization.
- Added checking of the WHERE clause (TIME_FOR_COMPARE) of the
accepted rows to ROR costs in get_best_ror_intersect()
- Removed '- 0.001' from 'join->best_read' and optimize_straight_join()
to ensure that the 'Last_query_cost' status variable contains the
same value as the one that was calculated by the optimizer.
- Take avg_io_cost() into account in handler::keyread_time() and
handler::read_time(). This should have no effect as it's 1.0 by
default, except for heap that overrides these functions.
- Some 'ref_or_null' accesses changed to 'range' because of cost
adjustments (main.order_by)
- Added scan type "scan_with_join_cache" for optimizer_trace. This is
just to show in the trace what kind of scan was used.
- When using 'scan_with_join_cache' take into account number of
preceding tables (as have to restore all fields for all previous
table combination when checking the where clause)
The new cost added is:
(row_combinations * ROW_COPY_COST * number_of_cached_tables).
This increases the cost of join buffering in proportion of the
number of tables in the join buffer. One effect is that full scans
are now done earlier as the cost is then smaller.
(main.join_outer_innodb, main.greedy_optimizer)
- Removed the usage of 'worst_seeks' in cost_for_index_read as it
caused wrong plans to be created; It prefered JT_EQ_REF even if it
would be much more expensive than a full table scan. A related
issue was that worst_seeks only applied to full lookup, not to
clustered or index only lookups, which is not consistent. This
caused some plans to use index scan instead of eq_ref (main.union)
- Changed federated block size from 4096 to 1500, which is the
typical size of an IO packet.
- Added costs for reading rows to Federated. Needed as there is no
caching of rows in the federated engine.
- Added ha_innobase::rnd_pos_time() cost function.
- A lot of extra things added to optimizer trace
- More costs, especially for materialization and index_merge.
- Make lables more uniform
- Fixed a lot of minor bugs
- Added 'trace_started()' around a lot of trace blocks.
- When calculating ORDER BY with LIMIT cost for using an index
the cost did not take into account the number of row retrivals
that has to be done or the cost of comparing the rows with the
WHERE clause. The cost calculated would be just a fraction of
the real cost. Now we calculate the cost as we do for ranges
and 'ref'.
- 'Using index for group-by' is used a bit more than before as
now take into account the WHERE clause cost when comparing
with 'ref' and prefer the method with fewer row combinations.
(main.group_min_max).
Bugs fixed:
- Fixed that we don't calculate TIME_FOR_COMPARE twice for some plans,
like in optimize_straight_join() and greedy_search()
- Fixed bug in save_explain_data where we could test for the wrong
index when displaying 'Using index'. This caused some old plans to
show 'Using index'. (main.subselect_innodb, main.subselect2)
- Fixed bug in get_best_ror_intersect() where 'min_cost' was not
updated, and the cost we compared with was not the one that was
used.
- Fixed very wrong cost calculation for priority queues in
check_if_pq_applicable(). (main.order_by now correctly uses priority
queue)
- When calculating cost of EQ_REF or REF, we added the cost of
comparing the WHERE clause with the found rows, not all row
combinations. This made ref and eq_ref to be regarded way to cheap
compared to other access methods.
- FORCE INDEX cost calculation didn't take into account clustered or
covered indexes.
- JT_EQ_REF cost was estimated as avg_io_cost(), which is half the
cost of a JT_REF key. This may be true for InnoDB primary key, but
not for other unique keys or other engines. Now we use handler
function to calculate the cost, which allows us to handle
consistently clustered, covered keys and not covered keys.
- ha_start_keyread() didn't call extra_opt() if keyread was already
enabled but still changed the 'keyread' variable (which is wrong).
Fixed by not doing anything if keyread is already enabled.
- multi_range_read_info_cost() didn't take into account io_cost when
calculating the cost of ranges.
- fix_semijoin_strategies_for_picked_join_order() used the wrong
record_count when calling best_access_path() for SJ_OPT_FIRST_MATCH
and SJ_OPT_LOOSE_SCAN.
- Hash joins didn't provide correct best_cost to the upper level, which
means that the cost for hash_joins more expensive than calculated
in best_access_path (a difference of 10x * TIME_OF_COMPARE).
This is fixed in the new code thanks to that we now include
TIME_OF_COMPARE cost in 'read_time'.
Other things:
- Added some 'if (thd->trace_started())' to speed up code
- Removed not used function Cost_estimate::is_zero()
- Simplified testing of HA_POS_ERROR in get_best_ror_intersect().
(No cost changes)
- Moved ha_start_keyread() from join_read_const_table() to join_read_const()
to enable keyread for all types of JT_CONST tables.
- Made a few very short functions inline in handler.h
Notes:
- In main.rowid_filter the join order of order and lineitem is swapped.
This is because the cost of doing a range fetch of lineitem(98 rows) is
almost as big as the whole join of order,lineitem. The filtering will
also ensure that we only have to do very small key fetches of the rows
in lineitem.
- main.index_merge_myisam had a few changes where we are now using
less keys for index_merge. This is because index scans are now more
expensive than before.
- handler->optimizer_cache_cost is updated in ha_external_lock().
This ensures that it is up to date per statements.
Not an optimal solution (for locked tables), but should be ok for now.
- 'DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a' does not take cost of
filesort into consideration when table scan is chosen.
(main.myisam_explain_non_select_all)
- perfschema.table_aggregate_global_* has changed because an update
on a table with 1 row will now use table scan instead of key lookup.
TODO in upcomming commits:
- Fix selectivity calculation for ranges with and without filtering and
when there is a ref access but scan is chosen.
For this we have to store the lowest known value for
'accepted_records' in the OPT_RANGE structure.
- Change that records_read does not include filtered rows.
- test_if_cheaper_ordering() needs to be updated to properly calculate
costs. This will fix tests like main.order_by_innodb,
main.single_delete_update
- Extend get_range_limit_read_cost() to take into considering
cost_for_index_read() if there where no quick keys. This will reduce
the computed cost for ORDER BY with LIMIT in some cases.
(main.innodb_ext_key)
- Fix that we take into account selectivity when counting the number
of rows we have to read when considering using a index table scan to
resolve ORDER BY.
- Add new calculation for rnd_pos_time() where we take into account the
benefit of reading multiple rows from the same page.
2021-11-01 11:34:24 +01:00
|
|
|
Size of IO operations. This is used to calculate time to scan a table.
|
|
|
|
See handler.cc::keyread_time
|
2009-10-30 19:50:56 +01:00
|
|
|
*/
|
|
|
|
if (flag & HA_STATUS_CONST)
|
Update row and key fetch cost models to take into account data copy costs
Before this patch, when calculating the cost of fetching and using a
row/key from the engine, we took into account the cost of finding a
row or key from the engine, but did not consistently take into account
index only accessed, clustered key or covered keys for all access
paths.
The cost of the WHERE clause (TIME_FOR_COMPARE) was not consistently
considered in best_access_path(). TIME_FOR_COMPARE was used in
calculation in other places, like greedy_search(), but was in some
cases (like scans) done an a different number of rows than was
accessed.
The cost calculation of row and index scans didn't take into account
the number of rows that where accessed, only the number of accepted
rows.
When using a filter, the cost of index_only_reads and cost of
accessing and disregarding 'filtered rows' where not taken into
account, which made filters cost less than there actually where.
To remedy the above, the following key & row fetch related costs
has been added:
- The cost of fetching and using a row is now split into different costs:
- key + Row fetch cost (as before) but multiplied with the variable
'optimizer_cache_cost' (default to 0.5). This allows the user to
tell the optimizer the likehood of finding the key and row in the
engine cache.
- ROW_COPY_COST, The cost copying a row from the engine to the
sql layer or creating a row from the join_cache to the record
buffer. Mostly affects table scan costs.
- ROW_LOOKUP_COST, the cost of fetching a row by rowid.
- KEY_COPY_COST the cost of finding the next key and copying it from
the engine to the SQL layer. This is used when we calculate the cost
index only reads. It makes index scans more expensive than before if
they cover a lot of rows. (main.index_merge_myisam)
- KEY_LOOKUP_COST, the cost of finding the first key in a range.
This replaces the old define IDX_LOOKUP_COST, but with a higher cost.
- KEY_NEXT_FIND_COST, the cost of finding the next key (and rowid).
when doing a index scan and comparing the rowid to the filter.
Before this cost was assumed to be 0.
All of the above constants/variables are now tuned to be somewhat in
proportion of executing complexity to each other. There is tuning
need for these in the future, but that can wait until the above are
made user variables as that will make tuning much easier.
To make the usage of the above easy, there are new (not virtual)
cost calclation functions in handler:
- ha_read_time(), like read_time(), but take optimizer_cache_cost into
account.
- ha_read_and_copy_time(), like ha_read_time() but take into account
ROW_COPY_TIME
- ha_read_and_compare_time(), like ha_read_and_copy_time() but take
TIME_FOR_COMPARE into account.
- ha_rnd_pos_time(). Read row with row id, taking ROW_COPY_COST
into account. This is used with filesort where we don't need
to execute the WHERE clause again.
- ha_keyread_time(), like keyread_time() but take
optimizer_cache_cost into account.
- ha_keyread_and_copy_time(), like ha_keyread_time(), but add
KEY_COPY_COST.
- ha_key_scan_time(), like key_scan_time() but take
optimizer_cache_cost nto account.
- ha_key_scan_and_compare_time(), like ha_key_scan_time(), but add
KEY_COPY_COST & TIME_FOR_COMPARE.
I also added some setup costs for doing different types of scans and
creating temporary tables (on disk and in memory). This encourages
the optimizer to not use these for simple 'a few row' lookups if
there are adequate key lookup strategies.
- TABLE_SCAN_SETUP_COST, cost of starting a table scan.
- INDEX_SCAN_SETUP_COST, cost of starting an index scan.
- HEAP_TEMPTABLE_CREATE_COST, cost of creating in memory
temporary table.
- DISK_TEMPTABLE_CREATE_COST, cost of creating an on disk temporary
table.
When calculating cost of fetching ranges, we had a cost of
IDX_LOOKUP_COST (0.125) for doing a key div for a new range. This is
now replaced with 'io_cost * KEY_LOOKUP_COST (1.0) *
optimizer_cache_cost', which matches the cost we use for 'ref' and
other key lookups. The effect is that the cost is now a bit higher
when we have many ranges for a key.
Allmost all calculation with TIME_FOR_COMPARE is now done in
best_access_path(). 'JOIN::read_time' now includes the full
cost for finding the rows in the table.
In the result files, many of the changes are now again close to what
they where before the "Update cost for hash and cached joins" commit,
as that commit didn't fix the filter cost (too complex to do
everything in one commit).
The above changes showed a lot of a lot of inconsistencies in
optimizer cost calculation. The main objective with the other changes
was to do calculation as similar (and accurate) as possible and to make
different plans more comparable.
Detailed list of changes:
- Calculate index_only_cost consistently and correctly for all scan
and ref accesses. The row fetch_cost and index_only_cost now
takes into account clustered keys, covered keys and index
only accesses.
- cost_for_index_read now returns both full cost and index_only_cost
- Fixed cost calculation of get_sweep_read_cost() to match other
similar costs. This is bases on the assumption that data is more
often stored on SSD than a hard disk.
- Replaced constant 2.0 with new define TABLE_SCAN_SETUP_COST.
- Some scan cost estimates did not take into account
TIME_FOR_COMPARE. Now all scan costs takes this into
account. (main.show_explain)
- Added session variable optimizer_cache_hit_ratio (default 50%). By
adjusting this on can reduce or increase the cost of index or direct
record lookups. The effect of the default is that key lookups is now
a bit cheaper than before. See usage of 'optimizer_cache_cost' in
handler.h.
- JOIN_TAB::scan_time() did not take into account index only scans,
which produced a wrong cost when index scan was used. Changed
JOIN_TAB:::scan_time() to take into consideration clustered and
covered keys. The values are now cached and we only have to call
this function once. Other calls are changed to use the cached
values. Function renamed to JOIN_TAB::estimate_scan_time().
- Fixed that most index cost calculations are done the same way and
more close to 'range' calculations. The cost is now lower than
before for small data sets and higher for large data sets as we take
into account how many keys are read (main.opt_trace_selectivity,
main.limit_rows_examined).
- Ensured that index_scan_cost() ==
range(scan_of_all_rows_in_table_using_one_range) +
MULTI_RANGE_READ_INFO_CONST. One effect of this is that if there
is choice of doing a full index scan and a range-index scan over
almost the whole table then index scan will be preferred (no
range-read setup cost). (innodb.innodb, main.show_explain,
main.range)
- Fixed the EQ_REF and REF takes into account clustered and covered
keys. This changes some plans to use covered or clustered indexes
as these are much cheaper. (main.subselect_mat_cost,
main.state_tables_innodb, main.limit_rows_examined)
- Rowid filter setup cost and filter compare cost now takes into
account fetching and checking the rowid (KEY_NEXT_FIND_COST).
(main.partition_pruning heap.heap_btree main.log_state)
- Added KEY_NEXT_FIND_COST to
Range_rowid_filter_cost_info::lookup_cost to account of the time
to find and check the next key value against the container
- Introduced ha_keyread_time(rows) that takes into account finding
the next row and copying the key value to 'record'
(KEY_COPY_COST).
- Introduced ha_key_scan_time() for calculating an index scan over
all rows.
- Added IDX_LOOKUP_COST to keyread_time() as a startup cost.
- Added index_only_fetch_cost() as a convenience function to
OPT_RANGE.
- keyread_time() cost is slightly reduced to prefer shorter keys.
(main.index_merge_myisam)
- All of the above caused some index_merge combinations to be
rejected because of cost (main.index_intersect). In some cases
'ref' where replaced with index_merge because of the low
cost calculation of get_sweep_read_cost().
- Some index usage moved from PRIMARY to a covering index.
(main.subselect_innodb)
- Changed cost calculation of filter to take KEY_LOOKUP_COST and
TIME_FOR_COMPARE into account. See sql_select.cc::apply_filter().
filter parameters and costs are now written to optimizer_trace.
- Don't use matchings_records_in_range() to try to estimate the number
of filtered rows for ranges. The reason is that we want to ensure
that 'range' is calculated similar to 'ref'. There is also more work
needed to calculate the selectivity when using ranges and ranges and
filtering. This causes filtering column in EXPLAIN EXTENDED to be
100.00 for some cases where range cannot use filtering.
(main.rowid_filter)
- Introduced ha_scan_time() that takes into account the CPU cost of
finding the next row and copying the row from the engine to
'record'. This causes costs of table scan to slightly increase and
some test to changed their plan from ALL to RANGE or ALL to ref.
(innodb.innodb_mysql, main.select_pkeycache)
In a few cases where scan time of very small tables have lower cost
than a ref or range, things changed from ref/range to ALL.
(main.myisam, main.func_group, main.limit_rows_examined,
main.subselect2)
- Introduced ha_scan_and_compare_time() which is like ha_scan_time()
but also adds the cost of the where clause (TIME_FOR_COMPARE).
- Added small cost for creating temporary table for
materialization. This causes some very small tables to use scan
instead of materialization.
- Added checking of the WHERE clause (TIME_FOR_COMPARE) of the
accepted rows to ROR costs in get_best_ror_intersect()
- Removed '- 0.001' from 'join->best_read' and optimize_straight_join()
to ensure that the 'Last_query_cost' status variable contains the
same value as the one that was calculated by the optimizer.
- Take avg_io_cost() into account in handler::keyread_time() and
handler::read_time(). This should have no effect as it's 1.0 by
default, except for heap that overrides these functions.
- Some 'ref_or_null' accesses changed to 'range' because of cost
adjustments (main.order_by)
- Added scan type "scan_with_join_cache" for optimizer_trace. This is
just to show in the trace what kind of scan was used.
- When using 'scan_with_join_cache' take into account number of
preceding tables (as have to restore all fields for all previous
table combination when checking the where clause)
The new cost added is:
(row_combinations * ROW_COPY_COST * number_of_cached_tables).
This increases the cost of join buffering in proportion of the
number of tables in the join buffer. One effect is that full scans
are now done earlier as the cost is then smaller.
(main.join_outer_innodb, main.greedy_optimizer)
- Removed the usage of 'worst_seeks' in cost_for_index_read as it
caused wrong plans to be created; It prefered JT_EQ_REF even if it
would be much more expensive than a full table scan. A related
issue was that worst_seeks only applied to full lookup, not to
clustered or index only lookups, which is not consistent. This
caused some plans to use index scan instead of eq_ref (main.union)
- Changed federated block size from 4096 to 1500, which is the
typical size of an IO packet.
- Added costs for reading rows to Federated. Needed as there is no
caching of rows in the federated engine.
- Added ha_innobase::rnd_pos_time() cost function.
- A lot of extra things added to optimizer trace
- More costs, especially for materialization and index_merge.
- Make lables more uniform
- Fixed a lot of minor bugs
- Added 'trace_started()' around a lot of trace blocks.
- When calculating ORDER BY with LIMIT cost for using an index
the cost did not take into account the number of row retrivals
that has to be done or the cost of comparing the rows with the
WHERE clause. The cost calculated would be just a fraction of
the real cost. Now we calculate the cost as we do for ranges
and 'ref'.
- 'Using index for group-by' is used a bit more than before as
now take into account the WHERE clause cost when comparing
with 'ref' and prefer the method with fewer row combinations.
(main.group_min_max).
Bugs fixed:
- Fixed that we don't calculate TIME_FOR_COMPARE twice for some plans,
like in optimize_straight_join() and greedy_search()
- Fixed bug in save_explain_data where we could test for the wrong
index when displaying 'Using index'. This caused some old plans to
show 'Using index'. (main.subselect_innodb, main.subselect2)
- Fixed bug in get_best_ror_intersect() where 'min_cost' was not
updated, and the cost we compared with was not the one that was
used.
- Fixed very wrong cost calculation for priority queues in
check_if_pq_applicable(). (main.order_by now correctly uses priority
queue)
- When calculating cost of EQ_REF or REF, we added the cost of
comparing the WHERE clause with the found rows, not all row
combinations. This made ref and eq_ref to be regarded way to cheap
compared to other access methods.
- FORCE INDEX cost calculation didn't take into account clustered or
covered indexes.
- JT_EQ_REF cost was estimated as avg_io_cost(), which is half the
cost of a JT_REF key. This may be true for InnoDB primary key, but
not for other unique keys or other engines. Now we use handler
function to calculate the cost, which allows us to handle
consistently clustered, covered keys and not covered keys.
- ha_start_keyread() didn't call extra_opt() if keyread was already
enabled but still changed the 'keyread' variable (which is wrong).
Fixed by not doing anything if keyread is already enabled.
- multi_range_read_info_cost() didn't take into account io_cost when
calculating the cost of ranges.
- fix_semijoin_strategies_for_picked_join_order() used the wrong
record_count when calling best_access_path() for SJ_OPT_FIRST_MATCH
and SJ_OPT_LOOSE_SCAN.
- Hash joins didn't provide correct best_cost to the upper level, which
means that the cost for hash_joins more expensive than calculated
in best_access_path (a difference of 10x * TIME_OF_COMPARE).
This is fixed in the new code thanks to that we now include
TIME_OF_COMPARE cost in 'read_time'.
Other things:
- Added some 'if (thd->trace_started())' to speed up code
- Removed not used function Cost_estimate::is_zero()
- Simplified testing of HA_POS_ERROR in get_best_ror_intersect().
(No cost changes)
- Moved ha_start_keyread() from join_read_const_table() to join_read_const()
to enable keyread for all types of JT_CONST tables.
- Made a few very short functions inline in handler.h
Notes:
- In main.rowid_filter the join order of order and lineitem is swapped.
This is because the cost of doing a range fetch of lineitem(98 rows) is
almost as big as the whole join of order,lineitem. The filtering will
also ensure that we only have to do very small key fetches of the rows
in lineitem.
- main.index_merge_myisam had a few changes where we are now using
less keys for index_merge. This is because index scans are now more
expensive than before.
- handler->optimizer_cache_cost is updated in ha_external_lock().
This ensures that it is up to date per statements.
Not an optimal solution (for locked tables), but should be ok for now.
- 'DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a' does not take cost of
filesort into consideration when table scan is chosen.
(main.myisam_explain_non_select_all)
- perfschema.table_aggregate_global_* has changed because an update
on a table with 1 row will now use table scan instead of key lookup.
TODO in upcomming commits:
- Fix selectivity calculation for ranges with and without filtering and
when there is a ref access but scan is chosen.
For this we have to store the lowest known value for
'accepted_records' in the OPT_RANGE structure.
- Change that records_read does not include filtered rows.
- test_if_cheaper_ordering() needs to be updated to properly calculate
costs. This will fix tests like main.order_by_innodb,
main.single_delete_update
- Extend get_range_limit_read_cost() to take into considering
cost_for_index_read() if there where no quick keys. This will reduce
the computed cost for ORDER BY with LIMIT in some cases.
(main.innodb_ext_key)
- Fix that we take into account selectivity when counting the number
of rows we have to read when considering using a index table scan to
resolve ORDER BY.
- Add new calculation for rnd_pos_time() where we take into account the
benefit of reading multiple rows from the same page.
2021-11-01 11:34:24 +01:00
|
|
|
stats.block_size= 1500; // Typical size of an TCP packet
|
2009-10-30 19:50:56 +01:00
|
|
|
|
2009-11-04 12:11:04 +01:00
|
|
|
if ((*iop)->table_metadata(&stats, share->table_name,
|
2018-02-06 13:55:58 +01:00
|
|
|
(uint)share->table_name_length, flag))
|
2009-10-30 19:50:56 +01:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flag & HA_STATUS_AUTO)
|
2009-11-04 12:11:04 +01:00
|
|
|
stats.auto_increment_value= (*iop)->last_insert_id();
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
If ::info created it's own transaction, close it. This happens in case
|
|
|
|
of show table status;
|
|
|
|
*/
|
2010-08-12 19:52:52 +02:00
|
|
|
tmp_txn->release(&tmp_io);
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
|
|
|
|
error:
|
2009-11-04 12:11:04 +01:00
|
|
|
if (iop && *iop)
|
2009-10-30 19:50:56 +01:00
|
|
|
{
|
2010-08-12 19:52:52 +02:00
|
|
|
my_printf_error((*iop)->error_code(), "Received error: %d : %s", MYF(0),
|
2010-07-16 15:43:46 +02:00
|
|
|
(*iop)->error_code(), (*iop)->error_str());
|
2009-10-30 19:50:56 +01:00
|
|
|
}
|
2010-07-16 15:43:46 +02:00
|
|
|
else if (remote_error_number != -1 /* error already reported */)
|
2009-10-30 19:50:56 +01:00
|
|
|
{
|
|
|
|
error_code= remote_error_number;
|
2015-07-06 19:24:14 +02:00
|
|
|
my_error(error_code, MYF(0), ER_THD(thd, error_code));
|
2009-10-30 19:50:56 +01:00
|
|
|
}
|
|
|
|
fail:
|
2010-08-12 19:52:52 +02:00
|
|
|
tmp_txn->release(&tmp_io);
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_RETURN(error_code);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@brief Handles extra signals from MySQL server
|
|
|
|
|
|
|
|
@param[in] operation Hint for storage engine
|
|
|
|
|
|
|
|
@return Operation Status
|
|
|
|
@retval 0 OK
|
|
|
|
*/
|
|
|
|
int ha_federatedx::extra(ha_extra_function operation)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_federatedx::extra");
|
|
|
|
switch (operation) {
|
|
|
|
case HA_EXTRA_IGNORE_DUP_KEY:
|
|
|
|
ignore_duplicates= TRUE;
|
|
|
|
break;
|
|
|
|
case HA_EXTRA_NO_IGNORE_DUP_KEY:
|
|
|
|
insert_dup_update= FALSE;
|
|
|
|
ignore_duplicates= FALSE;
|
|
|
|
break;
|
|
|
|
case HA_EXTRA_WRITE_CAN_REPLACE:
|
|
|
|
replace_duplicates= TRUE;
|
|
|
|
break;
|
|
|
|
case HA_EXTRA_WRITE_CANNOT_REPLACE:
|
|
|
|
/*
|
|
|
|
We use this flag to ensure that we do not create an "INSERT IGNORE"
|
|
|
|
statement when inserting new rows into the remote table.
|
|
|
|
*/
|
|
|
|
replace_duplicates= FALSE;
|
|
|
|
break;
|
|
|
|
case HA_EXTRA_INSERT_WITH_UPDATE:
|
|
|
|
insert_dup_update= TRUE;
|
|
|
|
break;
|
2010-07-23 22:37:21 +02:00
|
|
|
case HA_EXTRA_PREPARE_FOR_DROP:
|
|
|
|
table_will_be_deleted = TRUE;
|
|
|
|
break;
|
2009-10-30 19:50:56 +01:00
|
|
|
default:
|
|
|
|
/* do nothing */
|
|
|
|
DBUG_PRINT("info",("unhandled operation: %d", (uint) operation));
|
|
|
|
}
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@brief Reset state of file to after 'open'.
|
|
|
|
|
|
|
|
@detail This function is called after every statement for all tables
|
|
|
|
used by that statement.
|
|
|
|
|
|
|
|
@return Operation status
|
|
|
|
@retval 0 OK
|
|
|
|
*/
|
|
|
|
|
|
|
|
int ha_federatedx::reset(void)
|
|
|
|
{
|
2017-08-08 19:47:34 +02:00
|
|
|
THD *thd= ha_thd();
|
2010-08-12 19:52:52 +02:00
|
|
|
int error = 0;
|
|
|
|
|
2009-10-30 19:50:56 +01:00
|
|
|
insert_dup_update= FALSE;
|
|
|
|
ignore_duplicates= FALSE;
|
|
|
|
replace_duplicates= FALSE;
|
2010-08-12 19:52:52 +02:00
|
|
|
position_called= FALSE;
|
|
|
|
|
|
|
|
if (stored_result)
|
|
|
|
insert_dynamic(&results, (uchar*) &stored_result);
|
|
|
|
stored_result= 0;
|
|
|
|
|
|
|
|
if (results.elements)
|
|
|
|
{
|
|
|
|
federatedx_txn *tmp_txn;
|
|
|
|
federatedx_io *tmp_io= 0, **iop;
|
|
|
|
|
|
|
|
// external_lock may not have been called so txn may not be set
|
2017-08-08 19:47:34 +02:00
|
|
|
tmp_txn= get_txn(thd);
|
2010-08-12 19:52:52 +02:00
|
|
|
|
2017-08-08 19:47:34 +02:00
|
|
|
if (!*(iop= &io) && (error= tmp_txn->acquire(share, thd, TRUE, (iop= &tmp_io))))
|
2010-08-12 19:52:52 +02:00
|
|
|
{
|
|
|
|
DBUG_ASSERT(0); // Fail when testing
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint i= 0; i < results.elements; ++i)
|
|
|
|
{
|
|
|
|
FEDERATEDX_IO_RESULT *result= 0;
|
|
|
|
get_dynamic(&results, (uchar*) &result, i);
|
|
|
|
(*iop)->free_result(result);
|
|
|
|
}
|
|
|
|
tmp_txn->release(&tmp_io);
|
|
|
|
reset_dynamic(&results);
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
2009-10-30 19:50:56 +01:00
|
|
|
|
2010-08-12 19:52:52 +02:00
|
|
|
}
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Used to delete all rows in a table. Both for cases of truncate and
|
|
|
|
for cases where the optimizer realizes that all rows will be
|
|
|
|
removed as a result of a SQL statement.
|
|
|
|
|
|
|
|
Called from item_sum.cc by Item_func_group_concat::clear(),
|
|
|
|
Item_sum_count_distinct::clear(), and Item_func_group_concat::clear().
|
|
|
|
Called from sql_delete.cc by mysql_delete().
|
|
|
|
Called from sql_select.cc by JOIN::reinit().
|
|
|
|
Called from sql_union.cc by st_select_lex_unit::exec().
|
|
|
|
*/
|
|
|
|
|
|
|
|
int ha_federatedx::delete_all_rows()
|
|
|
|
{
|
2017-08-08 19:47:34 +02:00
|
|
|
THD *thd= ha_thd();
|
2009-10-30 19:50:56 +01:00
|
|
|
char query_buffer[FEDERATEDX_QUERY_BUFFER_SIZE];
|
|
|
|
String query(query_buffer, sizeof(query_buffer), &my_charset_bin);
|
|
|
|
int error;
|
|
|
|
DBUG_ENTER("ha_federatedx::delete_all_rows");
|
|
|
|
|
|
|
|
query.length(0);
|
|
|
|
|
|
|
|
query.set_charset(system_charset_info);
|
2018-05-07 13:36:52 +02:00
|
|
|
if (thd->lex->sql_command == SQLCOM_TRUNCATE)
|
|
|
|
query.append(STRING_WITH_LEN("TRUNCATE "));
|
|
|
|
else
|
|
|
|
query.append(STRING_WITH_LEN("DELETE FROM "));
|
2009-10-30 19:50:56 +01:00
|
|
|
append_ident(&query, share->table_name, share->table_name_length,
|
|
|
|
ident_quote_char);
|
|
|
|
|
|
|
|
/* no need for savepoint in autocommit mode */
|
2017-08-08 19:47:34 +02:00
|
|
|
if (!(thd->variables.option_bits & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
|
2009-10-30 19:50:56 +01:00
|
|
|
txn->stmt_autocommit();
|
|
|
|
|
|
|
|
/*
|
|
|
|
TRUNCATE won't return anything in mysql_affected_rows
|
|
|
|
*/
|
|
|
|
|
2017-08-08 19:47:34 +02:00
|
|
|
if ((error= txn->acquire(share, thd, FALSE, &io)))
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_RETURN(error);
|
|
|
|
|
|
|
|
if (io->query(query.ptr(), query.length()))
|
|
|
|
{
|
|
|
|
DBUG_RETURN(stash_remote_error());
|
|
|
|
}
|
|
|
|
stats.deleted+= stats.records;
|
|
|
|
stats.records= 0;
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
The idea with handler::store_lock() is the following:
|
|
|
|
|
|
|
|
The statement decided which locks we should need for the table
|
|
|
|
for updates/deletes/inserts we get WRITE locks, for SELECT... we get
|
|
|
|
read locks.
|
|
|
|
|
|
|
|
Before adding the lock into the table lock handler (see thr_lock.c)
|
|
|
|
mysqld calls store lock with the requested locks. Store lock can now
|
|
|
|
modify a write lock to a read lock (or some other lock), ignore the
|
|
|
|
lock (if we don't want to use MySQL table locks at all) or add locks
|
|
|
|
for many tables (like we do when we are using a MERGE handler).
|
|
|
|
|
|
|
|
Berkeley DB for federatedx changes all WRITE locks to TL_WRITE_ALLOW_WRITE
|
|
|
|
(which signals that we are doing WRITES, but we are still allowing other
|
|
|
|
reader's and writer's.
|
|
|
|
|
|
|
|
When releasing locks, store_lock() are also called. In this case one
|
|
|
|
usually doesn't have to do anything.
|
|
|
|
|
|
|
|
In some exceptional cases MySQL may send a request for a TL_IGNORE;
|
|
|
|
This means that we are requesting the same lock as last time and this
|
|
|
|
should also be ignored. (This may happen when someone does a flush
|
|
|
|
table when we have opened a part of the tables, in which case mysqld
|
|
|
|
closes and reopens the tables and tries to get the same locks at last
|
|
|
|
time). In the future we will probably try to remove this.
|
|
|
|
|
|
|
|
Called from lock.cc by get_lock_data().
|
|
|
|
*/
|
|
|
|
|
|
|
|
THR_LOCK_DATA **ha_federatedx::store_lock(THD *thd,
|
|
|
|
THR_LOCK_DATA **to,
|
|
|
|
enum thr_lock_type lock_type)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_federatedx::store_lock");
|
|
|
|
if (lock_type != TL_IGNORE && lock.type == TL_UNLOCK)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Here is where we get into the guts of a row level lock.
|
|
|
|
If TL_UNLOCK is set
|
|
|
|
If we are not doing a LOCK TABLE or DISCARD/IMPORT
|
|
|
|
TABLESPACE, then allow multiple writers
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((lock_type >= TL_WRITE_CONCURRENT_INSERT &&
|
|
|
|
lock_type <= TL_WRITE) && !thd->in_lock_tables)
|
|
|
|
lock_type= TL_WRITE_ALLOW_WRITE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
In queries of type INSERT INTO t1 SELECT ... FROM t2 ...
|
|
|
|
MySQL would use the lock TL_READ_NO_INSERT on t2, and that
|
|
|
|
would conflict with TL_WRITE_ALLOW_WRITE, blocking all inserts
|
|
|
|
to t2. Convert the lock to a normal read lock to allow
|
|
|
|
concurrent inserts to t2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (lock_type == TL_READ_NO_INSERT && !thd->in_lock_tables)
|
|
|
|
lock_type= TL_READ;
|
|
|
|
|
|
|
|
lock.type= lock_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
*to++= &lock;
|
|
|
|
|
|
|
|
DBUG_RETURN(to);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int test_connection(MYSQL_THD thd, federatedx_io *io,
|
|
|
|
FEDERATEDX_SHARE *share)
|
|
|
|
{
|
|
|
|
char buffer[FEDERATEDX_QUERY_BUFFER_SIZE];
|
|
|
|
String str(buffer, sizeof(buffer), &my_charset_bin);
|
|
|
|
FEDERATEDX_IO_RESULT *resultset= NULL;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
str.length(0);
|
|
|
|
str.append(STRING_WITH_LEN("SELECT * FROM "));
|
2010-08-12 19:52:52 +02:00
|
|
|
append_identifier(thd, &str, share->table_name,
|
2009-10-30 19:50:56 +01:00
|
|
|
share->table_name_length);
|
|
|
|
str.append(STRING_WITH_LEN(" WHERE 1=0"));
|
|
|
|
|
|
|
|
if ((retval= io->query(str.ptr(), str.length())))
|
|
|
|
{
|
2022-09-28 16:45:25 +02:00
|
|
|
snprintf(buffer, sizeof(buffer), "database: '%s' username: '%s' hostname: '%s'",
|
2011-07-02 22:12:12 +02:00
|
|
|
share->database, share->username, share->hostname);
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_PRINT("info", ("error-code: %d", io->error_code()));
|
|
|
|
my_error(ER_CANT_CREATE_FEDERATED_TABLE, MYF(0), buffer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
resultset= io->store_result();
|
|
|
|
|
|
|
|
io->free_result(resultset);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
create() does nothing, since we have no local setup of our own.
|
|
|
|
FUTURE: We should potentially connect to the foreign database and
|
|
|
|
*/
|
|
|
|
|
|
|
|
int ha_federatedx::create(const char *name, TABLE *table_arg,
|
|
|
|
HA_CREATE_INFO *create_info)
|
|
|
|
{
|
|
|
|
int retval;
|
2015-12-06 01:40:51 +01:00
|
|
|
THD *thd= ha_thd();
|
2009-10-30 19:50:56 +01:00
|
|
|
FEDERATEDX_SHARE tmp_share; // Only a temporary share, to test the url
|
|
|
|
federatedx_txn *tmp_txn;
|
|
|
|
federatedx_io *tmp_io= NULL;
|
|
|
|
DBUG_ENTER("ha_federatedx::create");
|
|
|
|
|
2013-04-09 16:19:18 +02:00
|
|
|
if ((retval= parse_url(thd->mem_root, &tmp_share, table_arg->s, 1)))
|
2009-10-30 19:50:56 +01:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* loopback socket connections hang due to LOCK_open mutex */
|
2019-11-22 12:30:13 +01:00
|
|
|
if (0 == strcmp(tmp_share.hostname, my_localhost) && !tmp_share.port)
|
2009-10-30 19:50:56 +01:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
/*
|
|
|
|
If possible, we try to use an existing network connection to
|
|
|
|
the remote server. To ensure that no new FEDERATEDX_SERVER
|
|
|
|
instance is created, we pass NULL in get_server() TABLE arg.
|
|
|
|
*/
|
2011-07-13 21:10:18 +02:00
|
|
|
mysql_mutex_lock(&federatedx_mutex);
|
2009-10-30 19:50:56 +01:00
|
|
|
tmp_share.s= get_server(&tmp_share, NULL);
|
2011-07-13 21:10:18 +02:00
|
|
|
mysql_mutex_unlock(&federatedx_mutex);
|
2010-08-12 19:52:52 +02:00
|
|
|
|
2009-10-30 19:50:56 +01:00
|
|
|
if (tmp_share.s)
|
|
|
|
{
|
|
|
|
tmp_txn= get_txn(thd);
|
2017-08-08 19:47:34 +02:00
|
|
|
if (!(retval= tmp_txn->acquire(&tmp_share, thd, TRUE, &tmp_io)))
|
2009-10-30 19:50:56 +01:00
|
|
|
{
|
|
|
|
retval= test_connection(thd, tmp_io, &tmp_share);
|
2010-08-12 19:52:52 +02:00
|
|
|
tmp_txn->release(&tmp_io);
|
2009-10-30 19:50:56 +01:00
|
|
|
}
|
|
|
|
free_server(tmp_txn, tmp_share.s);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FEDERATEDX_SERVER server;
|
|
|
|
|
MDEV-22775 [HY000][1553] Changing name of primary key column with foreign key constraint fails.
Problem:
The problem happened because of a conceptual flaw in the server code:
a. The table level CHARSET/COLLATE clause affected all data types,
including numeric and temporal ones:
CREATE TABLE t1 (a INT) CHARACTER SET utf8 [COLLATE utf8_general_ci];
In the above example, the Column_definition_attributes
(and then the FRM record) for the column "a" erroneously inherited
"utf8" as its character set.
b. The "ALTER TABLE t1 CONVERT TO CHARACTER SET csname" statement
also erroneously affected Column_definition_attributes::charset
for numeric and temporal data types and wrote "csname" as their
character set into FRM files.
So now we have arbitrary non-relevant charset ID values for numeric
and temporal data types in all FRM files in the world :)
The code in the server and the other engines did not seem to be affected
by this flaw. Only InnoDB inplace ALTER was affected.
Solution:
Fixing the code in the way that only character string data types
(CHAR,VARCHAR,TEXT,ENUM,SET):
- inherit the table level CHARSET/COLLATE clause
- get the charset value according to "CONVERT TO CHARACTER SET csname".
Numeric and temporal data types now always get &my_charset_numeric
in Column_definition_attributes::charset and always write its ID into FRM files:
- no matter what the table level CHARSET/COLLATE clause is, and
- no matter what "CONVERT TO CHARACTER SET" says.
Details:
1. Adding helper classes to pass small parts of HA_CREATE_INFO
into Type_handler methods:
- Column_derived_attributes - to pass table level CHARSET/COLLATE,
so columns that do not have explicit CHARSET/COLLATE clauses
can derive them from the table level, e.g.
CREATE TABLE t1 (a VARCHAR(1), b CHAR(1)) CHARACTER SET utf8;
- Column_bulk_alter_attributes - to pass bulk attribute changes
generated by the ALTER related code. These bulk changes affect
multiple columns at the same time:
ALTER TABLE ... CONVERT TO CHARACTER SET csname;
Note, passing the whole HA_CREATE_INFO directly to Type_handler
would not be good: HA_CREATE_INFO is huge and would need not desired
dependencies in sql_type.h and sql_type.cc. The Type_handler API should
use smallest possible data types!
2. Type_handler::Column_definition_prepare_stage1() is now responsible
to set Column_definition::charset properly, according to the data type,
for example:
- For string data types, Column_definition_attributes::charset is set from
the table level CHARSET/COLLATE clause (if not specified explicitly in
the column definition).
- For numeric and temporal fields, Column_definition_attributes::charset is
set to &my_charset_numeric, no matter what the table level
CHARSET/COLLATE says.
- For GEOMETRY, Column_definition_attributes::charset is set to
&my_charset_bin, no matter what the table level CHARSET/COLLATE says.
Previously this code (setting `charset`) was outside of of
Column_definition_prepare_stage1(), namely in
mysql_prepare_create_table(), and was erroneously called for
all data types.
3. Adding Type_handler::Column_definition_bulk_alter(), to handle
"ALTER TABLE .. CONVERT TO". Previously this code was inside
get_sql_field_charset() and was erroneously called for all data types.
4. Removing the Schema_specification_st parameter from
Type_handler::Column_definition_redefine_stage1().
Column_definition_attributes::charset is now fully properly initialized by
Column_definition_prepare_stage1(). So we don't need access to the
table level CHARSET/COLLATE clause in Column_definition_redefine_stage1()
any more.
5. Other changes:
- Removing global function get_sql_field_charset()
- Moving the part of the former get_sql_field_charset(), which was
responsible to inherit the table level CHARSET/COLLATE clause to
new methods:
-- Column_definition_attributes::explicit_or_derived_charset() and
-- Column_definition::prepare_charset_for_string().
This code is only needed for string data types.
Previously it was erroneously called for all data types.
- Moving another part, which was responsible to apply the
"CONVERT TO" clause, to
Type_handler_general_purpose_string::Column_definition_bulk_alter().
- Replacing the call for get_sql_field_charset() in sql_partition.cc
to sql_field->explicit_or_derived_charset() - it is perfectly enough.
The old code was redundant: get_sql_field_charset() was called from
sql_partition.cc only when there were no a "CONVERT TO CHARACTER SET"
clause involved, so its purpose was only to inherit the table
level CHARSET/COLLATE clause.
- Moving the code handling the BINCMP_FLAG flag from
mysql_prepare_create_table() to
Column_definition::prepare_charset_for_string():
This code is responsible to resolve the BINARY comparison style
into the corresponding _bin collation, to do the following transparent
rewrite:
CREATE TABLE t1 (a VARCHAR(10) BINARY) CHARSET utf8; ->
CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_bin);
This code is only needed for string data types.
Previously it was erroneously called for all data types.
6. Renaming Table_scope_and_contents_source_pod_st::table_charset
to alter_table_convert_to_charset, because the only purpose it's used for
is handlering "ALTER .. CONVERT". The new name is much more self-descriptive.
2021-03-25 03:55:18 +01:00
|
|
|
// It's possibly wrong to use alter_table_convert_to_charset here.
|
|
|
|
fill_server(thd->mem_root, &server, &tmp_share,
|
|
|
|
create_info->alter_table_convert_to_charset);
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
#ifndef DBUG_OFF
|
2011-07-13 21:10:18 +02:00
|
|
|
mysql_mutex_init(fe_key_mutex_FEDERATEDX_SERVER_mutex,
|
|
|
|
&server.mutex, MY_MUTEX_INIT_FAST);
|
|
|
|
mysql_mutex_lock(&server.mutex);
|
2009-10-30 19:50:56 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
tmp_io= federatedx_io::construct(thd->mem_root, &server);
|
|
|
|
|
|
|
|
retval= test_connection(thd, tmp_io, &tmp_share);
|
|
|
|
|
|
|
|
#ifndef DBUG_OFF
|
2011-07-13 21:10:18 +02:00
|
|
|
mysql_mutex_unlock(&server.mutex);
|
|
|
|
mysql_mutex_destroy(&server.mutex);
|
2009-10-30 19:50:56 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
delete tmp_io;
|
|
|
|
}
|
|
|
|
|
|
|
|
error:
|
|
|
|
DBUG_RETURN(retval);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ha_federatedx::stash_remote_error()
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_federatedx::stash_remote_error()");
|
|
|
|
if (!io)
|
|
|
|
DBUG_RETURN(remote_error_number);
|
|
|
|
remote_error_number= io->error_code();
|
2013-04-17 19:42:34 +02:00
|
|
|
strmake_buf(remote_error_buf, io->error_str());
|
2009-10-30 19:50:56 +01:00
|
|
|
if (remote_error_number == ER_DUP_ENTRY ||
|
|
|
|
remote_error_number == ER_DUP_KEY)
|
|
|
|
DBUG_RETURN(HA_ERR_FOUND_DUPP_KEY);
|
|
|
|
DBUG_RETURN(HA_FEDERATEDX_ERROR_WITH_REMOTE_SYSTEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ha_federatedx::get_error_message(int error, String* buf)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_federatedx::get_error_message");
|
|
|
|
DBUG_PRINT("enter", ("error: %d", error));
|
|
|
|
if (error == HA_FEDERATEDX_ERROR_WITH_REMOTE_SYSTEM)
|
|
|
|
{
|
|
|
|
buf->append(STRING_WITH_LEN("Error on remote system: "));
|
|
|
|
buf->qs_append(remote_error_number);
|
|
|
|
buf->append(STRING_WITH_LEN(": "));
|
Reduce usage of strlen()
Changes:
- To detect automatic strlen() I removed the methods in String that
uses 'const char *' without a length:
- String::append(const char*)
- Binary_string(const char *str)
- String(const char *str, CHARSET_INFO *cs)
- append_for_single_quote(const char *)
All usage of append(const char*) is changed to either use
String::append(char), String::append(const char*, size_t length) or
String::append(LEX_CSTRING)
- Added STRING_WITH_LEN() around constant string arguments to
String::append()
- Added overflow argument to escape_string_for_mysql() and
escape_quotes_for_mysql() instead of returning (size_t) -1 on overflow.
This was needed as most usage of the above functions never tested the
result for -1 and would have given wrong results or crashes in case
of overflows.
- Added Item_func_or_sum::func_name_cstring(), which returns LEX_CSTRING.
Changed all Item_func::func_name()'s to func_name_cstring()'s.
The old Item_func_or_sum::func_name() is now an inline function that
returns func_name_cstring().str.
- Changed Item::mode_name() and Item::func_name_ext() to return
LEX_CSTRING.
- Changed for some functions the name argument from const char * to
to const LEX_CSTRING &:
- Item::Item_func_fix_attributes()
- Item::check_type_...()
- Type_std_attributes::agg_item_collations()
- Type_std_attributes::agg_item_set_converter()
- Type_std_attributes::agg_arg_charsets...()
- Type_handler_hybrid_field_type::aggregate_for_result()
- Type_handler_geometry::check_type_geom_or_binary()
- Type_handler::Item_func_or_sum_illegal_param()
- Predicant_to_list_comparator::add_value_skip_null()
- Predicant_to_list_comparator::add_value()
- cmp_item_row::prepare_comparators()
- cmp_item_row::aggregate_row_elements_for_comparison()
- Cursor_ref::print_func()
- Removes String_space() as it was only used in one cases and that
could be simplified to not use String_space(), thanks to the fixed
my_vsnprintf().
- Added some const LEX_CSTRING's for common strings:
- NULL_clex_str, DATA_clex_str, INDEX_clex_str.
- Changed primary_key_name to a LEX_CSTRING
- Renamed String::set_quick() to String::set_buffer_if_not_allocated() to
clarify what the function really does.
- Rename of protocol function:
bool store(const char *from, CHARSET_INFO *cs) to
bool store_string_or_null(const char *from, CHARSET_INFO *cs).
This was done to both clarify the difference between this 'store' function
and also to make it easier to find unoptimal usage of store() calls.
- Added Protocol::store(const LEX_CSTRING*, CHARSET_INFO*)
- Changed some 'const char*' arrays to instead be of type LEX_CSTRING.
- class Item_func_units now used LEX_CSTRING for name.
Other things:
- Fixed a bug in mysql.cc:construct_prompt() where a wrong escape character
in the prompt would cause some part of the prompt to be duplicated.
- Fixed a lot of instances where the length of the argument to
append is known or easily obtain but was not used.
- Removed some not needed 'virtual' definition for functions that was
inherited from the parent. I added override to these.
- Fixed Ordered_key::print() to preallocate needed buffer. Old code could
case memory overruns.
- Simplified some loops when adding char * to a String with delimiters.
2020-08-12 19:29:55 +02:00
|
|
|
buf->append(remote_error_buf, strlen(remote_error_buf));
|
2010-11-23 23:08:48 +01:00
|
|
|
/* Ensure string ends with \0 */
|
|
|
|
(void) buf->c_ptr_safe();
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
remote_error_number= 0;
|
|
|
|
remote_error_buf[0]= '\0';
|
|
|
|
}
|
2010-11-23 23:08:48 +01:00
|
|
|
DBUG_PRINT("exit", ("message: %s", buf->c_ptr_safe()));
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_RETURN(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ha_federatedx::start_stmt(MYSQL_THD thd, thr_lock_type lock_type)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("ha_federatedx::start_stmt");
|
|
|
|
DBUG_ASSERT(txn == get_txn(thd));
|
|
|
|
|
|
|
|
if (!txn->in_transaction())
|
|
|
|
{
|
|
|
|
txn->stmt_begin();
|
2020-02-27 16:00:43 +01:00
|
|
|
trans_register_ha(thd, FALSE, ht, 0);
|
2009-10-30 19:50:56 +01:00
|
|
|
}
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ha_federatedx::external_lock(MYSQL_THD thd, int lock_type)
|
|
|
|
{
|
|
|
|
int error= 0;
|
|
|
|
DBUG_ENTER("ha_federatedx::external_lock");
|
|
|
|
|
|
|
|
if (lock_type == F_UNLCK)
|
|
|
|
txn->release(&io);
|
|
|
|
else
|
|
|
|
{
|
2010-07-23 22:37:21 +02:00
|
|
|
table_will_be_deleted = FALSE;
|
2009-10-30 19:50:56 +01:00
|
|
|
txn= get_txn(thd);
|
2017-08-08 19:47:34 +02:00
|
|
|
if (!(error= txn->acquire(share, ha_thd(), lock_type == F_RDLCK, &io)) &&
|
2009-10-30 19:50:56 +01:00
|
|
|
(lock_type == F_WRLCK || !io->is_autocommit()))
|
|
|
|
{
|
|
|
|
if (!thd_test_options(thd, (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
|
|
|
|
{
|
|
|
|
txn->stmt_begin();
|
2020-02-27 16:00:43 +01:00
|
|
|
trans_register_ha(thd, FALSE, ht, 0);
|
2009-10-30 19:50:56 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
txn->txn_begin();
|
2020-02-27 16:00:43 +01:00
|
|
|
trans_register_ha(thd, TRUE, ht, 0);
|
2009-10-30 19:50:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-09-11 19:32:38 +02:00
|
|
|
int ha_federatedx::savepoint_set(MYSQL_THD thd, void *sv)
|
2009-10-30 19:50:56 +01:00
|
|
|
{
|
|
|
|
int error= 0;
|
2024-09-11 19:32:38 +02:00
|
|
|
federatedx_txn *txn= (federatedx_txn *) thd_get_ha_data(thd, federatedx_hton);
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_ENTER("ha_federatedx::savepoint_set");
|
|
|
|
|
|
|
|
if (txn && txn->has_connections())
|
|
|
|
{
|
|
|
|
if (txn->txn_begin())
|
2024-09-11 19:32:38 +02:00
|
|
|
trans_register_ha(thd, TRUE, federatedx_hton, 0);
|
2009-10-30 19:50:56 +01:00
|
|
|
|
|
|
|
txn->sp_acquire((ulong *) sv);
|
|
|
|
|
|
|
|
DBUG_ASSERT(1 < *(ulong *) sv);
|
|
|
|
}
|
|
|
|
|
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-09-11 19:32:38 +02:00
|
|
|
int ha_federatedx::savepoint_rollback(MYSQL_THD thd, void *sv)
|
2009-10-30 19:50:56 +01:00
|
|
|
{
|
|
|
|
int error= 0;
|
2024-09-11 19:32:38 +02:00
|
|
|
federatedx_txn *txn= (federatedx_txn *) thd_get_ha_data(thd, federatedx_hton);
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_ENTER("ha_federatedx::savepoint_rollback");
|
|
|
|
|
|
|
|
if (txn)
|
|
|
|
error= txn->sp_rollback((ulong *) sv);
|
|
|
|
|
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-09-11 19:32:38 +02:00
|
|
|
int ha_federatedx::savepoint_release(MYSQL_THD thd, void *sv)
|
2009-10-30 19:50:56 +01:00
|
|
|
{
|
|
|
|
int error= 0;
|
2024-09-11 19:32:38 +02:00
|
|
|
federatedx_txn *txn= (federatedx_txn *) thd_get_ha_data(thd, federatedx_hton);
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_ENTER("ha_federatedx::savepoint_release");
|
|
|
|
|
|
|
|
if (txn)
|
|
|
|
error= txn->sp_release((ulong *) sv);
|
|
|
|
|
|
|
|
DBUG_RETURN(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-09-11 19:32:38 +02:00
|
|
|
int ha_federatedx::commit(MYSQL_THD thd, bool all)
|
2009-10-30 19:50:56 +01:00
|
|
|
{
|
|
|
|
int return_val;
|
2024-09-11 19:32:38 +02:00
|
|
|
federatedx_txn *txn= (federatedx_txn *) thd_get_ha_data(thd, federatedx_hton);
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_ENTER("ha_federatedx::commit");
|
|
|
|
|
|
|
|
if (all)
|
|
|
|
return_val= txn->txn_commit();
|
|
|
|
else
|
|
|
|
return_val= txn->stmt_commit();
|
|
|
|
|
|
|
|
DBUG_PRINT("info", ("error val: %d", return_val));
|
|
|
|
DBUG_RETURN(return_val);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-09-11 19:32:38 +02:00
|
|
|
int ha_federatedx::rollback(MYSQL_THD thd, bool all)
|
2009-10-30 19:50:56 +01:00
|
|
|
{
|
|
|
|
int return_val;
|
2024-09-11 19:32:38 +02:00
|
|
|
federatedx_txn *txn= (federatedx_txn *) thd_get_ha_data(thd, federatedx_hton);
|
2009-10-30 19:50:56 +01:00
|
|
|
DBUG_ENTER("ha_federatedx::rollback");
|
|
|
|
|
|
|
|
if (all)
|
|
|
|
return_val= txn->txn_rollback();
|
|
|
|
else
|
|
|
|
return_val= txn->stmt_rollback();
|
|
|
|
|
|
|
|
DBUG_PRINT("info", ("error val: %d", return_val));
|
|
|
|
DBUG_RETURN(return_val);
|
|
|
|
}
|
|
|
|
|
2013-04-09 16:19:18 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Federated supports assisted discovery, like
|
|
|
|
CREATE TABLE t1 CONNECTION="mysql://joe:pass@192.168.1.111/federated/t1";
|
|
|
|
but not a fully automatic discovery where a table magically appear
|
|
|
|
on any use (like, on SELECT * from t1).
|
|
|
|
*/
|
|
|
|
int ha_federatedx::discover_assisted(handlerton *hton, THD* thd,
|
|
|
|
TABLE_SHARE *table_s, HA_CREATE_INFO *info)
|
|
|
|
{
|
|
|
|
int error= HA_ERR_NO_CONNECTION;
|
|
|
|
FEDERATEDX_SHARE tmp_share;
|
|
|
|
CHARSET_INFO *cs= system_charset_info;
|
|
|
|
MYSQL mysql;
|
|
|
|
char buf[1024];
|
|
|
|
String query(buf, sizeof(buf), cs);
|
2018-05-07 13:36:52 +02:00
|
|
|
static LEX_CSTRING cut_clause={STRING_WITH_LEN(" WITH SYSTEM VERSIONING")};
|
2020-05-29 10:45:19 +02:00
|
|
|
static LEX_CSTRING cut_start={STRING_WITH_LEN("GENERATED ALWAYS AS ROW START")};
|
|
|
|
static LEX_CSTRING cut_end={STRING_WITH_LEN("GENERATED ALWAYS AS ROW END")};
|
|
|
|
static LEX_CSTRING set_ts={STRING_WITH_LEN("DEFAULT TIMESTAMP'1971-01-01 00:00:00'")};
|
2018-05-07 13:36:52 +02:00
|
|
|
int cut_offset;
|
2013-04-09 16:19:18 +02:00
|
|
|
MYSQL_RES *res;
|
|
|
|
MYSQL_ROW rdata;
|
|
|
|
ulong *rlen;
|
2013-04-17 22:37:06 +02:00
|
|
|
my_bool my_true= 1;
|
2023-09-04 15:32:36 +02:00
|
|
|
my_bool my_false= 0;
|
2013-04-09 16:19:18 +02:00
|
|
|
|
|
|
|
if (parse_url(thd->mem_root, &tmp_share, table_s, 1))
|
|
|
|
return HA_WRONG_CREATE_OPTION;
|
|
|
|
|
|
|
|
mysql_init(&mysql);
|
2020-08-22 01:08:59 +02:00
|
|
|
mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, cs->cs_name.str);
|
2018-05-07 13:36:52 +02:00
|
|
|
mysql_options(&mysql, MYSQL_OPT_USE_THREAD_SPECIFIC_MEMORY, (char*)&my_true);
|
2023-09-04 15:32:36 +02:00
|
|
|
mysql_options(&mysql, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, &my_false);
|
2013-04-09 16:19:18 +02:00
|
|
|
|
|
|
|
if (!mysql_real_connect(&mysql, tmp_share.hostname, tmp_share.username,
|
|
|
|
tmp_share.password, tmp_share.database,
|
|
|
|
tmp_share.port, tmp_share.socket, 0))
|
|
|
|
goto err1;
|
|
|
|
|
|
|
|
if (mysql_real_query(&mysql, STRING_WITH_LEN("SET SQL_MODE=NO_TABLE_OPTIONS")))
|
|
|
|
goto err1;
|
|
|
|
|
|
|
|
query.copy(STRING_WITH_LEN("SHOW CREATE TABLE "), cs);
|
|
|
|
append_ident(&query, tmp_share.table_name,
|
|
|
|
tmp_share.table_name_length, ident_quote_char);
|
|
|
|
|
|
|
|
if (mysql_real_query(&mysql, query.ptr(), query.length()))
|
|
|
|
goto err1;
|
|
|
|
|
|
|
|
if (!((res= mysql_store_result(&mysql))))
|
|
|
|
goto err1;
|
|
|
|
|
|
|
|
if (!(rdata= mysql_fetch_row(res)) || !((rlen= mysql_fetch_lengths(res))))
|
|
|
|
goto err2;
|
|
|
|
|
|
|
|
query.copy(rdata[1], rlen[1], cs);
|
2018-05-07 13:36:52 +02:00
|
|
|
cut_offset= (int)query.length() - (int)cut_clause.length;
|
|
|
|
if (cut_offset > 0 && !memcmp(query.ptr() + cut_offset,
|
|
|
|
cut_clause.str, cut_clause.length))
|
2020-05-29 10:45:19 +02:00
|
|
|
{
|
2018-05-07 13:36:52 +02:00
|
|
|
query.length(cut_offset);
|
2020-05-29 10:45:19 +02:00
|
|
|
const char *ptr= strstr(query.ptr(), cut_start.str);
|
|
|
|
if (ptr)
|
|
|
|
{
|
|
|
|
query.replace((uint32) (ptr - query.ptr()), (uint32) cut_start.length,
|
|
|
|
set_ts.str, (uint32) set_ts.length);
|
|
|
|
}
|
|
|
|
ptr= strstr(query.ptr(), cut_end.str);
|
|
|
|
if (ptr)
|
|
|
|
{
|
|
|
|
query.replace((uint32) (ptr - query.ptr()), (uint32) cut_end.length,
|
|
|
|
set_ts.str, (uint32) set_ts.length);
|
|
|
|
}
|
|
|
|
}
|
2013-04-09 16:20:59 +02:00
|
|
|
query.append(STRING_WITH_LEN(" CONNECTION='"), cs);
|
|
|
|
query.append_for_single_quote(table_s->connect_string.str,
|
|
|
|
table_s->connect_string.length);
|
|
|
|
query.append('\'');
|
2013-04-09 16:19:18 +02:00
|
|
|
|
|
|
|
error= table_s->init_from_sql_statement_string(thd, true,
|
|
|
|
query.ptr(), query.length());
|
|
|
|
|
|
|
|
err2:
|
|
|
|
mysql_free_result(res);
|
|
|
|
err1:
|
|
|
|
if (error)
|
|
|
|
my_error(ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0), mysql_error(&mysql));
|
|
|
|
mysql_close(&mysql);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-30 19:50:56 +01:00
|
|
|
struct st_mysql_storage_engine federatedx_storage_engine=
|
|
|
|
{ MYSQL_HANDLERTON_INTERFACE_VERSION };
|
|
|
|
|
2019-02-12 22:11:32 +01:00
|
|
|
my_bool use_pushdown;
|
|
|
|
static MYSQL_SYSVAR_BOOL(pushdown, use_pushdown, 0,
|
|
|
|
"Use query fragments pushdown capabilities", NULL, NULL, FALSE);
|
2019-02-13 17:55:38 +01:00
|
|
|
static struct st_mysql_sys_var* sysvars[]= { MYSQL_SYSVAR(pushdown), NULL };
|
2019-02-12 22:11:32 +01:00
|
|
|
|
|
|
|
#include "federatedx_pushdown.cc"
|
|
|
|
|
2010-06-14 18:58:52 +02:00
|
|
|
maria_declare_plugin(federatedx)
|
2010-04-01 16:34:51 +02:00
|
|
|
{
|
|
|
|
MYSQL_STORAGE_ENGINE_PLUGIN,
|
|
|
|
&federatedx_storage_engine,
|
|
|
|
"FEDERATED",
|
|
|
|
"Patrick Galbraith",
|
2020-12-20 20:07:38 +01:00
|
|
|
"Allows one to access tables on other MariaDB servers, supports transactions and more",
|
2010-04-01 16:34:51 +02:00
|
|
|
PLUGIN_LICENSE_GPL,
|
|
|
|
federatedx_db_init, /* Plugin Init */
|
|
|
|
federatedx_done, /* Plugin Deinit */
|
2013-04-09 16:19:18 +02:00
|
|
|
0x0201 /* 2.1 */,
|
2010-04-01 16:34:51 +02:00
|
|
|
NULL, /* status variables */
|
2019-02-12 22:11:32 +01:00
|
|
|
sysvars, /* system variables */
|
2013-04-09 16:19:18 +02:00
|
|
|
"2.1", /* string version */
|
2014-03-19 09:56:46 +01:00
|
|
|
MariaDB_PLUGIN_MATURITY_STABLE /* maturity */
|
2010-04-01 16:34:51 +02:00
|
|
|
}
|
|
|
|
maria_declare_plugin_end;
|