1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00
Commit Graph

712 Commits

Author SHA1 Message Date
Oleksandr Byelkin
89c7e2b9c7 Merge branch '10.11' into 11.4 2025-06-17 09:50:22 +02:00
Marko Mäkelä
1c7209e828 Merge 10.6 into 10.11 2025-05-21 07:36:35 +03:00
Yuchen Pei
c626715439 MDEV-35452 [fixup] fix spider/bugfix.perfschema view protocol
mtr with --view-protocol creates new threads
2025-04-30 10:38:44 +10:00
Yuchen Pei
76e8e24b0b Merge branch '10.5' into 10.6 2025-04-30 10:35:11 +10:00
Yuchen Pei
5c92b27d54 MDEV-36633 MDEV-35452 spider/bugfix.mdev_33434 reports wrong error in view protocol
With view protocol collation_connection is reset in mysql_make_view in
the "SELECT * FROM mysqltest_tmp_v" query. In the case of
spider/bugfix.mdev_33434, it is reset to latin1_swedish_ci, with the
latin1 charset.

This results in no conversion needed since it is the same as
character_set_client and the corresponding argument in the udf remains
unchanged, with "dummy" srv value. Thus the reported error is

1477: 'The foreign server name you are trying to reference does not exist. Data source error:  dummy'

Without view protocol, the character_set_connection ucs2 setting in
the test survives, and the conversion results in empty connection
parameters, and the reported error is 1429
ER_CONNECT_TO_FOREIGN_DATA_SOURCE

This failure is irrelevant to the test, or to spider at all. Therefore
we disable view protocol for the statement.
2025-04-28 14:40:16 +10:00
Yuchen Pei
b1446080d1 MDEV-36476 MDEV-35452 Disable view protocol for spider tests where thread metadata could prevent lock wait timeout
In spider/bugfix.mdev_29352, with flush tables with read lock,
statements blocked in THD::has_read_only_protection() by checking
THD::global_read_lock could result in view protocol to "hang" waiting
for acquiring mdl in another THD.

In spider/bugfix.mdev_34555, within an XA transaction, statements
blocked by trans_check() by checking thd->transaction->xid_state could
result in view protocol to "hang" for the same reason.

Therefore we disable view protocol for relevant statements in these
tests.
2025-04-28 14:40:16 +10:00
Yuchen Pei
08793310fb MDEV-36478 MDEV-35452 Remove blocks testing SELECT SQL_CALC_FOUND_ROWS from spider tests
Spider tables do not support SELECT SQL_CALC_FOUND_ROWS and the
correct test output is a coincidence. Debugging shows that the
limit_found_rows field was last updated in an unrelated statement:

SELECT STRAIGHT_JOIN a.a, a.b, date_format(b.c, '%Y-%m-%d %H:%i:%s')\nFROM ta_l a, tb_l b WHERE a.a = b.a ORDER BY a.a

As a byproduct, this fixes the "wrong found_rows() results" when
running these tests with view protocol.
2025-04-28 14:40:16 +10:00
Yuchen Pei
9089a75b7f MDEV-36477 MDEV-35452 Fix Spider tests with view protocol fail with "Failed to drop view: 0: "
The failure is caused by exec $stmt where $stmt has two queries.
mtr with view protocol transforms the first query into a view, leaving
the second query executed in the usual way. mtr being oblivious about
the second query then does not handle its results, resulting in
CR_COMMANDS_OUT_OF_SYNC. We disable view protocol for such edge cases.
After fixing these "Failed to drop view: 0: " further failures emerge
from two of the tests, which are the same problem as MDEV-36454, so we
fix them to by disabling view protocol for the relevant SELECTs.
2025-04-28 14:40:16 +10:00
Oleksandr Byelkin
a8d4642375 Merge branch '10.11' into 11.4 2025-04-26 10:53:02 +02:00
Oleksandr Byelkin
20b818f45e Merge branch '10.6' into 10.11 2025-04-21 11:23:11 +02:00
Oleksandr Byelkin
a135551569 Merge branch '10.5' into 10.6 2025-04-21 10:43:17 +02:00
Yuchen Pei
f89f8aa313 MDEV-36357 MDEV-35452 Temporarily disable view protocol for a query in spider/bg.basic_sql
It should be re-enabled once MDEV-36357 is fixed.

Also added some documentation to spider result operations.
2025-04-17 15:37:31 +10:00
Julius Goryavsky
1a013cea95 Merge branch '10.6' into '10.11' 2025-04-16 03:34:40 +02:00
Julius Goryavsky
88dfa6bcee Merge branch '10.5' into '10.6' 2025-04-15 01:49:48 +02:00
Yuchen Pei
b6392c292e MDEV-36454 MDEV-35452 Fix spider view protocol test failures caused by tampering of order by items
With view protocol, a SELECT statement is transformed into two
statements:

1. CREATE OR REPLACE VIEW mysqltest_tmp_v AS SELECT ...
2. SELECT * FROM mysqltest_tmp_v

The first statement reconstructed the query, which is executed in the
second statement.

The reconstruction often replaces aliases in ORDER BY by the original
item.

For example, in the test spider/bugfix.mdev_29008 the query

SELECT MIN(t2.a) AS f1, t1.b AS f2 FROM tbl_a AS t1 JOIN tbl_a AS t2 GROUP BY f2 ORDER BY f1, f2;

is transformed to

"select min(`t2`.`a`) AS `f1`,`t1`.`b` AS `f2` from (`auto_test_local`.`tbl_a` `t1` join `auto_test_local`.`tbl_a` `t2`) group by `t1`.`b` order by min(`t2`.`a`),`t1`.`b`"

In such cases, spider constructs different queries to execute at the
data node. So we disable view protocol for such queries.
2025-04-08 11:26:02 +10:00
Yuchen Pei
8866fba00a MDEV-36454 MDEV-35452 Fix spider view protocol test failures caused by different queries constructed without GBH
With view protocol, often during optimization, the GBH is not created
because join->tables_list is the view mysqltest_tmp_v which has MEMORY
as engine which does not have GBH implemented.

In such cases, if without view protocol the test takes a path that
does create a spider GBH, the resulting queries sent to the data node
often differ.

Therefore we disable view protocol for these statements.
2025-04-08 11:26:01 +10:00
Yuchen Pei
dabd51c391 MDEV-36335 MDEV-35452 Disable view protocol when calling spider_copy_tables in tests
Spider needs to lock the spider table when executing the udf, but the
server layer would have already locked tables in view protocol because
it transforms the query:

select spider_copy_table('t', 0, 1)

to two queries

create or replace view mysqltest_tmp_v as select
spider_copy_table('t', 0, 1);
select * from mysqltest_tmp_v;

So spider justifiably errors out in this case by checking on
thd->derived_tables and thd->locks in spider_copy_tables_body()
2025-04-08 11:26:01 +10:00
Yuchen Pei
0f7c9146cf MDEV-36452 MDEV-35452 Fix udf output temp field name in spider tests with --view-protocol 2025-04-08 11:26:01 +10:00
Yuchen Pei
25f1e6f565 MDEV-36307 MDEV-35452 Do not create spider group by handler when dealing with derived tables or view and at least one select item is constant
If one of the selected field is a MIN or MAX and it has been optimized
into a constant, it is not added to the temp table used by a group by
handler (GBH). The GBH therefore cannot store results to this missing
field.

On the other hand, when SELECTing from a view or a derived table,
TMP_TABLE_ALL_COLUMNS is set. If the query has no group by or order
by, an Item_temptable_field is created for this MIN/MAX field and
added to the JOIN. Since the GBH could not store results to the
corresponding field in the temp table, the value of this
Item_temptable_field remains NULL. And the NULL value is passed to the
record, then the temp row, and finally output as the (wrong) result.

To fix this, we opt to not creating a spider GBH when a view or
derived table is involved.

This fixes spider/bugfix.mdev_26345 for --view-protocol

Also fixed a comment:

TABLE_LIST::belong_to_derived is NULL if the table belongs to a
derived table that has non-MERGE type.
2025-04-08 11:25:44 +10:00
Yuchen Pei
59962ae2b3 MDEV-36442 MDEV-35452 Fix --view-protocol for spider tests with SELECT arguments of SELECT statements
Running mtr --view-protocol transforms SELECT statements to a CREATE
OR REPLACE VIEW of the statement, followed by SELECT from the view.
When thus when spider tests check the query log for select statements,
it often output a different one with --view-protocol compared to
without.

By adding disable/enable_view_protocol pairs to these statements. Most
of these statements are surrounded by existing
disable/enable_ps[2]_protocol pairs.

Acked-by: Yuchen Pei <ycp@mariadb.com>
2025-04-08 11:25:44 +10:00
Marko Mäkelä
3ae8f114e2 Merge 10.11 into 11.4 2025-04-02 10:15:08 +03:00
Julius Goryavsky
74f0b99edf Merge branch '10.6' into '10.11' 2025-04-02 06:33:39 +02:00
Julius Goryavsky
03c31ab099 Merge branch '10.5' into '10.6' 2025-04-02 04:43:24 +02:00
Yuchen Pei
866c06ac2d MDEV-36441 MDEV-35452 Fix extra spider_same_server_link warnings in view-protocol
With --view-protocol, mtr transforms a SELECT query to two queries:

1. CREATE OR REPLACE VIEW mysqltest_tmp_v AS ...
2. SELECT * FROM mysqltest_tmp_v

where ... is the original query. Further mtr may run the first query
in a separate connection.

On the other hand if the data node is the same as the spider node,
spider_same_server_link is required for connection to the data node.

Therefore, for mtr --view-protocol tests often spider_same_server_link
needs to be set on both session and global levels. In this patch we
add the missing "SET GLOBAL spider_same_server_link=1" queries to
tests that fail with wrong results due to this issue.

It does not fix --view-protocol for all the affected tests, because
there are other issues fixed in subsequent patches.
2025-04-01 14:53:04 +11:00
Marko Mäkelä
f5bd250f5b Merge 10.11 into 11.4 2025-03-28 13:55:21 +02:00
Marko Mäkelä
ab0f2a00b6 Merge 10.6 into 10.11 2025-03-27 08:01:47 +02:00
Marko Mäkelä
49a6baec56 Merge 10.11 into 11.4 2025-03-03 11:07:56 +02:00
Yuchen Pei
7bb0885397 fixup of MDEV-35959 2025-02-27 04:13:00 +01:00
Julius Goryavsky
e3d7d5ca26 Merge branch '10.5' into '10.6' 2025-02-27 04:02:33 +01:00
Yuchen Pei
92d5882ffd MDEV-35807 Case-insensitive wrappers in spider
Continued on the work in MDEV-32157
18990f0073
2025-02-26 15:46:05 +11:00
Yuchen Pei
fcfb89a897 MDEV-35874 Spider: add missing skips when fetching results
In MDEV-26345 77ed235d50 a bitmap is
introduced to skip spider GBH SELECTed constant fields when storing
the results from the data node. Unfortunately this bitmap was not used
in all applicable calls. This patch fixes it. The test covers most of
the calls, with the exception of
spider_db_store_result_for_reuse_cursor(), which is not covered in
existing tests, because it is only called when limit_mode()==1, which
is not the case for any spider backend wrapper.
2025-02-26 15:45:17 +11:00
Yuchen Pei
49d976feaa MDEV-29605 Reset queued ping info of all spider connections associated with a closed spider handler
A spider_conn may outlive its associated ha_spider (in the field
queued_ping_spider) used for connecting to and pinging the data
node (a call to spider_db_ping(), guarded by the boolean field
queued_ping). In a call to ha_spider::close() (which is often preceded
with the deletion of the ha_spider itself), many cleanups happen,
including freeing the associated spider_share, which is used by the
spider_conn in spider_db_ping. Therefore it is necessary to reset both
the queued_ping_spider and queued_ping fields, so that any further
spider interaction with the data node will not trigger the call using
the ha_spider including its freed spider_share.

Also out of caution added an assert and internal error in case a
connection has not been established (the db_conn field of type
MYSQL * is NULL), and attempt to connect is skipped because both
queued_connect and queued_ping are false. Note that this unlikely (if
not impossible) scenario would not be a regression caused by this
change, as it strictly falls under the scenario of this bug.
2025-02-24 14:47:58 +11:00
Yuchen Pei
0ca98e834d MDEV-35959 Store the error message at the net layer when reading a packet from the server
This ensures that the error message is populated when the reading
fails with ER_NET_READ_INTERRUPTED, which at the client layer returns
without storing any error message as there is no corresponding CR_
error code.

Patch originally by Sergei Golubchik <serg@mariadb.com>
2025-02-04 11:44:16 +11:00
Sergei Golubchik
7d657fda64 Merge branch '10.11 into 11.4 2025-01-30 12:01:11 +01:00
Sergei Golubchik
e69f8cae1a Merge branch '10.6' into 10.11 2025-01-30 11:55:13 +01:00
Sergei Golubchik
066e8d6aea Merge branch '10.5' into 10.6 2025-01-29 11:17:38 +01:00
Yuchen Pei
1f306d395d MDEV-34849 Spider: update conn->queue_connect_share when needed
Update conn->queue_connect_share in spider_check_trx_and_get_conn to
avoid use-after-free.

There are two branches in spider_check_trx_and_get_conn, often called
at the beginning of a spider DML, depending on whether an update of
various spider fields is needed. If it is determined to be needed, the
updating may NULL the connections associated with the spider handler,
which subsequently causes a call to spider_get_conn() which updates
conn->queued_connect_share with the SPIDER_SHARE associated with the
spider handler.

We make it so that conn->queued_connect_share is updated regardless of
the branch it enters, so that it will not be a stale and potentially
already freed one.
2025-01-22 11:20:07 +11:00
Marko Mäkelä
98dbe3bfaf Merge 10.5 into 10.6 2025-01-20 09:57:37 +02:00
Yuchen Pei
8d6c9ef001 MDEV-34925 Fix segv on thd in spider recovery.
Create temporary thd whenever needed in spider xa commit / recovery.
This prevents crash during recovery.
2025-01-20 10:50:45 +11:00
Oleksandr Byelkin
0d35fe6e57 MDEV-35326: Memory Leak in init_io_cache_ext upon SHUTDOWN
The problems were that:
1) resources was freed "asimetric" normal execution in send_eof,
 in case of error in destructor.
2) destructor was not called in case of SP for result objects.
(so if the last SP execution ended with error resorces was not
freeded on reinit before execution (cleanup() called before next
execution) and destructor also was not called due to lack of
delete call for the object)

Result cleanup() renamed to reset_for_next_ps_execution() to better
reflect function().

All result method revised and freeing resources made "symetric".

Destructor of result object called for SP.

Added skipped invalidation in case of error in insert.

Removed misleading naming of reset(thd) (could be mixed with
with reset()).
2025-01-13 10:04:27 +01:00
Marko Mäkelä
17f01186f5 Merge 10.11 into 11.4 2025-01-09 07:58:08 +02:00
Marko Mäkelä
3f914afd3a Merge 10.6 into 10.11 2025-01-02 12:39:56 +02:00
Yuchen Pei
671f80c738 Merge branch '10.5' into 10.6 2024-12-17 11:06:09 +11:00
Yuchen Pei
77c9917663 MDEV-34716 Fix mysql.servers socket max length too short
The limit of socket length on unix according to libc is 108, see
sockaddr_un::sun_path, but in the table it is a string of max length
64, which results in truncation of socket and failure to connect by
plugins using servers such as spider.
2024-12-17 10:40:57 +11:00
Kristian Nielsen
db8dfe0162 After-merge fix, spider deprecation warning
Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
2024-12-05 12:08:12 +01:00
Kristian Nielsen
0f47db8525 Merge 10.11 -> 11.4
Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
2024-12-05 11:01:42 +01:00
Kristian Nielsen
e7c6cdd842 Merge 10.6 -> 10.11
Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
2024-12-05 10:11:58 +01:00
Julius Goryavsky
cefdc3e67d Merge branch '10.5' into '10.6' 2024-12-03 13:08:12 +01:00
Yuchen Pei
d0fcac4450 MDEV-35422 Fix spider group by handler trying to use fake group by fields
This is a fixup of MDEV-26345 commit
77ed235d50.

In MDEV-26345 the spider group by handler was updated so that it uses
the item_ptr fields of Query::group_by and Query::order_by, instead of
item. This was and is because the call to
join->set_items_ref_array(join->items1) during the execution stage,
just before the execution replaces the order-by / group-by item arrays
with Item_temptable_field.

Spider traverses the item tree during the group by handler (gbh)
creation at the end of the optimization stage, and decides a gbh could
handle the execution of the query. Basically spider gbh can handle the
execution if it can construct a well-formed query, executes on the
data node, and store the results in the correct places. If so, it will
create one, otherwise it will return NULL and the execution will use
the usual handler (ha_spider instead of spider_group_by_handler). To
that end, the general principle is the items checked for creation
should be the same items later used for query construciton. Since in
MDEV-26345 we changed to use the item_ptr field instead of item field
of order-by and group-by in query construction, in this patch we do
the same for the gbh creation.

The item_ptr field could be the uninitialised NULL value during the
gbh creation. This is because the optimizer may replace a DISTINCT
with a GROUP BY, which only happens if the original GROUP BY is empty.
It creates the artificial GROUP BY by calling create_distinct_group(),
which creates the corresponding ORDER object with item field aligning
with somewhere in ref_pointer_array, but leaving item_ptr to be NULL.
When spider finds out that item_ptr is NULL, it knows there's some
optimizer skullduggery and it is passed a query different from the
original. Without a clear contract between the server layer and the
gbh, it is better to be safe than sorry and not create the gbh in this
case.

Also add a check and error reporting for the unlikely case of item_ptr
changing from non-NULL at gbh construction to NULL at execution to
prevent server crash.

Also, we remove a check added in MDEV-29480 of order by items being
aggregate functions. That check was added with the premise that spider
was including auxiliary SELECT items which is referenced by ORDER BY
items. This premise was no longer true since MDEV-26345, and caused
problems such as MDEV-29546, which was fixed by MDEV-26345.
2024-12-03 10:32:42 +11:00
Marko Mäkelä
2719cc4925 Merge 10.11 into 11.4 2024-12-02 11:35:34 +02:00