Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: 当存在decimal数据类型时且派生表中包含union all的查询语句不支持 #1873

Closed
haitaoguan opened this issue Jun 12, 2023 · 19 comments
Labels
A-bug Something isn't working prio: high High priority

Comments

@haitaoguan
Copy link
Collaborator

haitaoguan commented Jun 12, 2023

create table t1(c1 decimal(5,2));
insert into t1 values(111.22);

create table t2(id int);
insert into t2 values(11122);

select xxx.x from (select c1 as x from t1 union all select 1 as x from t2) xxx;
ERROR 1105 (HY000): The query includes syntax that is not supported by the storage engine. Tianmu: UNION of non-matching columns (column no 0) .

SELECT a.start_amount
  FROM (SELECT a.balance start_amount
          FROM (SELECT a.account_id, a.balance
                  FROM C1AM_ACCT_DAY a, C1MD_BANK_ACCT b
                 WHERE a.account_id = b.ROW_ID) a
          LEFT JOIN C1AM_BANK_LIST b
            on b.account_id = a.account_id
        UNION ALL
        SELECT 0 start_amount
          FROM C1AM_BANK_LIST a, C1MD_BANK_ACCT b
         WHERE a.account_id = b.ROW_ID) a
ERROR 1105 (HY000): The query includes syntax that is not supported by the storage engine. Tianmu: UNION of non-matching columns (column no 0) .
@haitaoguan haitaoguan added A-feature feature with good idea prio: high High priority labels Jun 12, 2023
@haitaoguan
Copy link
Collaborator Author

SELECT a.start_amount
  FROM (SELECT a.balance start_amount
          FROM (SELECT a.account_id, a.balance
                  FROM C1AM_ACCT_DAY a, C1MD_BANK_ACCT b
                 WHERE a.account_id = b.ROW_ID) a
          LEFT JOIN C1AM_BANK_LIST b
            on b.account_id = a.account_id
        UNION ALL
        SELECT 1.00 start_amount
          FROM C1AM_BANK_LIST a, C1MD_BANK_ACCT b
         WHERE a.account_id = b.ROW_ID) a

......
|   469026770.70 |
|   469047549.00 |
|   469047387.53 |
|   469046299.18 |
|   469043774.80 |
......

@adofsauron
Copy link
Collaborator

如果是客户POC场景的问题,直接提成BUG单高优先级处理客户问题。非客户场景,转为feature

@adofsauron adofsauron added A-bug Something isn't working and removed A-feature feature with good idea labels Jun 12, 2023
@adofsauron adofsauron changed the title feature:The query is unsupported when extracting data from the union all result set of decimal and integer bug: The query is unsupported when extracting data from the union all result set of decimal and integer Jun 12, 2023
@adofsauron
Copy link
Collaborator

好,那就先搞这个

@adofsauron adofsauron self-assigned this Jun 12, 2023
@adofsauron adofsauron changed the title bug: The query is unsupported when extracting data from the union all result set of decimal and integer bug: 派生表中包含union all的查询语句不支持 Jun 13, 2023
@adofsauron adofsauron changed the title bug: 派生表中包含union all的查询语句不支持 bug: 当存在decimal数据类型时且派生表中包含union all的查询语句不支持 Jun 13, 2023
@adofsauron
Copy link
Collaborator

是的,问题出在decimal这个数据类型上,把decimal给换成其他类型就可以了

@adofsauron
Copy link
Collaborator

Decimal: sign: 0 intg: 1 frac: 0 { 000000000 }
Record: 80 00 00 00 00 00 00 00 00

@adofsauron
Copy link
Collaborator

Decimal: sign: 0 intg: 3 frac: 2 { 000000111, 220000000 }
Record: 80 00 00 00 00 00 00 6F 16

@adofsauron
Copy link
Collaborator

对派生表的临时表中的decimal属性做记录

$10 = (Field_new_decimal) {
  <Field_num> = {
    <Field> = {
      <Proto_field> = {
        _vptr.Proto_field = 0x433dbd8 <vtable for Field_new_decimal+16>
      }, 
      members of Field: 
      ptr = 0x7fc1f401b039 "\200", 
      m_null_ptr = 0x7fc1f401b038 "\377\200", 
      m_is_tmp_nullable = false, 
      m_is_tmp_null = false, 
      m_count_cuted_fields_saved = (CHECK_FIELD_WARN | CHECK_FIELD_ERROR_FOR_NULL | unknown: 2408550284), 
      table = 0x7fc1f49da580, 
      orig_table = 0x7fc1f49da580, 
      table_name = 0x7fc1f49da670, 
      field_name = 0x7fc1f4006a10 "x", 
      comment = {
        str = 0x326f0f9 "", 
        length = 0
      }, 
      key_start = {
        map = 0
      }, 
      part_of_key = {
        map = 0
      }, 
      part_of_sortkey = {
        map = 0
      }, 
      part_of_key_not_extended = {
        map = 0
      }, 
      unireg_check = Field::NONE, 
      field_length = 20, 
      flags = 0, 
      field_index = 0, 
      null_bit = 2 '\002', 
      is_created_from_null_item = false, 
      m_indexed = false, 
      m_warnings_pushed = 0, 
      gcol_info = 0x0, 
      stored_in_db = true
    }, 
    members of Field_num: 
    dec = 2 '\002', 
    zerofill = false, 
    unsigned_flag = false
  }, 
--Type <RET> for more, q to quit, c to continue without paging--
  members of Field_new_decimal: 
  precision = 18, 
  bin_size = 9
}


@adofsauron
Copy link
Collaborator

在序列化的时候做检测:

        if (!encoder_created) {
          std::stringstream ss;
          ss << "UNION of non-matching columns (column no " << i << ") .";
          throw common::NotImplementedException(ss.str());
        }

@adofsauron
Copy link
Collaborator

问题也出在这么一个投影上, 这倒是一个不新鲜的问题

select 1 as x from t2

@adofsauron
Copy link
Collaborator

一个非常有趣的问题,如果不对界限设置边界,那么就会被这种无穷无尽的sql的方言给拖死进去

@adofsauron
Copy link
Collaborator

保持在thd中的错误信息

  m_message_text = "The query includes syntax that is not supported by the storage engine. Tianmu: UNION of non-matching columns (column no 0) .", '\000' <repeats 387 times>, 

@adofsauron
Copy link
Collaborator

除此之外还有另一个惊奇的代码逻辑:

    if (max_ints + max_scale > 18) {
      std::stringstream ss;
      ss << "UNION of non-matching columns (column no " << 0 << ") .";
      throw common::NotImplementedException(ss.str());
    }

@adofsauron
Copy link
Collaborator

(gdb) p max_ints
$1 = 19
(gdb) p max_scale
$2 = 2

@adofsauron
Copy link
Collaborator

decimal的精度限定在18位以内

@adofsauron
Copy link
Collaborator

这块也有一些恶心的做法,但是没那么明显,可以分析这里的临时表创建的列属性的限制,对于后续运算使用,这里存在魔数并不奇怪,但是关键地方就是在于条件本身的处理

@adofsauron
Copy link
Collaborator

列属性使用了bigint

(gdb) p type2
$3 = {
  type = Tianmu::common::ColumnType::BIGINT, 
  unsigned_flag_ = false, 
  precision = 19, 
  scale = 0, 
  internal_size = 8, 
  display_size = 20, 
  collation = {
    collation = 0x44674e0 <my_charset_bin>, 
    derivation = DERIVATION_NONE, 
    repertoire = 3
  }, 
  fmt = Tianmu::common::PackFmt::DEFAULT, 
  flag = std::bitset
}

@adofsauron
Copy link
Collaborator

bigint和int的精度限度不同,这里区别对待

@adofsauron
Copy link
Collaborator

adofsauron commented Jun 14, 2023

3a36d0e1b179ac123e05870f123f7171

@adofsauron
Copy link
Collaborator

至此,客户POC的这个场景被成功的解决,遗留的问题就是何时彻底处理bigint,这里仅做备忘录,不处理bigint

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-bug Something isn't working prio: high High priority
Projects
None yet
Development

No branches or pull requests

2 participants