[MDEV-29623] Bogus ER_OUT_OF_RESOURCES upon LEFT JOIN from spider and non-spider table Created: 2022-09-24  Updated: 2023-11-28

Status: Stalled
Project: MariaDB Server
Component/s: Storage Engine - Spider
Affects Version/s: 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 10.10
Fix Version/s: 10.4, 10.5, 10.6

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Yuchen Pei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

--source plugin/spider/spider/include/init_spider.inc
 
SET spider_same_server_link= on;
eval create server s foreign data wrapper mysql options (host "127.0.0.1", database "test", user "root", port $MASTER_MYPORT);
 
CREATE TABLE t1 (a int) ENGINE=MyISAM;
CREATE TABLE t2 (b int) ENGINE=MyISAM;
CREATE TABLE t1_spider (a int) ENGINE=SPIDER COMMENT = "wrapper 'mysql', srv 's', table 't1'";
 
SELECT * FROM t1_spider LEFT JOIN t2 ON a = b WHERE b = 3 OR a = 4;
 
# Cleanup
 
DROP TABLE t1_spider, t1, t2;
DROP SERVER s;
 
--source plugin/spider/spider/include/deinit_spider.inc

10.3 ce23802c

mysqltest: At line 10: query 'SELECT * FROM t1_spider LEFT JOIN t2 ON a = b WHERE b = 3 OR a = 4' failed: 1041: Out of memory.

Reproducible on all of 10.3-10.10, with MyISAM or Aria for the joining table.



 Comments   
Comment by Nayuta Yanagisawa (Inactive) [ 2022-09-26 ]

--echo #
--echo # MDEV-29623 Bogus ER_OUT_OF_RESOURCES upon LEFT JOIN from spider and non-spider table
--echo #
 
--disable_query_log
--disable_result_log
--source ../../t/test_init.inc
--enable_result_log
--enable_query_log
 
--connection child2_1
CREATE DATABASE auto_test_remote;
USE auto_test_remote;
CREATE TABLE tbl_a (a int) ENGINE=MyISAM;
 
--connection master_1
CREATE DATABASE auto_test_local;
USE auto_test_local;
eval CREATE TABLE tbl_a (
    a INT
) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='table "tbl_a", srv "s_2_1"';
CREATE TABLE tbl_b (b int) ENGINE=MyISAM;
SHOW CREATE TABLE tbl_b;
 
--error 1041
SELECT * FROM tbl_a LEFT JOIN tbl_b ON a = b WHERE b = 3 OR a = 4;
 
--connection child2_1
DROP DATABASE auto_test_remote;
 
--connection master_1
DROP DATABASE auto_test_local;
 
--disable_query_log
--disable_result_log
--source ../t/test_deinit.inc
--enable_query_log
--enable_result_log

Comment by Nayuta Yanagisawa (Inactive) [ 2022-09-26 ]

HA_ERR_OUT_OF_MEM is set here

int spider_db_open_item_int(...)
{
  ...
  if (str)
  {
    ...
    if (!(tmp_str2 = item->val_str(tmp_str.get_str())))
    {
      error_num = HA_ERR_OUT_OF_MEM;
      goto end;
    }
    tmp_str.mem_calc();
    ...
  }
  ...
}

because has_value() returns false.

String *Item_cache_int::val_str(String *str)
{
  DBUG_ASSERT(fixed == 1);
  if (!has_value())
    return NULL;
  str->set_int(value, unsigned_flag, default_charset());
  return str;
}

Comment by Nayuta Yanagisawa (Inactive) [ 2022-09-26 ]

Item::val_str() returns NULL if and only if the Item represents NULL. So, returning HA_ERR_OUT_OF_MEM is wrong when Item::val_str() returns NULL.

Comment by Yuchen Pei [ 2023-05-16 ]

The test in the first comment[1] passes on 11.1 4e5b771e980edfdad5c5414aa62c81d409d585a4.

Never mind, I noticed ERROR HY000: Out of memory. in the test result at the 11.1 commit mentioned above

[1] https://jira.mariadb.org/browse/MDEV-29623?focusedCommentId=235804&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-235804

Generated at Thu Feb 08 10:10:02 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.