Skip to content

[Bug]: Cannot find tableID 272437 in table mo_increment_columns #16888

Closed

Description

@ck89119

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main, 1.2-dev

Commit ID

6e13861

Other Environment Information

- Hardware parameters:
- OS type:
- Others:

Actual Behavior

mysql> select * from information_schema.tables;
ERROR 1146 (HY000): no such table .Cannot find tableID 272437 in table mo_increment_columns, accountid 0, txn: 019014ae74a870a08b8f52f5c50bde74/Active/S:1718333895844401000-1	col_name: task_id, table_id: 272390
	col_name: cron_task_id, table_id: 272392
	col_name: task_id, table_id: 272394
	col_name: id, table_id: 272402
	col_name: id, table_id: 272403
	col_name: __mo_fake_pk_col, table_id: 272405
	col_name: __mo_fake_pk_col, table_id: 272406
	col_name: id, table_id: 272407
	col_name: id, table_id: 272408
	col_name: id, table_

Expected Behavior

No response

Steps to Reproduce

as actual behavior

Additional information

No response

Activity

  1. added
    kind/bug
    on Jun 14, 2024
  2. ck89119 commented on Jun 14, 2024

    @ck89119
    ContributorAuthor

    information_schema.TABLES的schema是这样的:

    CREATE VIEW information_schema.TABLES AS
    SELECT 'def'                                                                                 AS TABLE_CATALOG,
           reldatabase                                                                           AS TABLE_SCHEMA,
           relname                                                                               AS TABLE_NAME,
           (case
                when relkind = 'v' and (reldatabase = 'mo_catalog' or reldatabase = 'information_schema') then 'SYSTEM VIEW'
                when relkind = 'v' then 'VIEW'
                when relkind = 'e' then 'EXTERNAL TABLE'
                when relkind = 'r' then 'BASE TABLE'
                else 'INTERNAL TABLE' end)                                                       AS TABLE_TYPE,
           if(relkind = 'r', 'Tae', NULL)                                                        AS ENGINE,
           if(relkind = 'v', NULL, 10)                                                           AS VERSION,
           'Compressed'                                                                          AS ROW_FORMAT,
           if(relkind = 'v', NULL, 0)                                                            AS TABLE_ROWS,
           if(relkind = 'v', NULL, 0)                                                            AS AVG_ROW_LENGTH,
           if(relkind = 'v', NULL, 0)                                                            AS DATA_LENGTH,
           if(relkind = 'v', NULL, 0)                                                            AS MAX_DATA_LENGTH,
           if(relkind = 'v', NULL, 0)                                                            AS INDEX_LENGTH,
           if(relkind = 'v', NULL, 0)                                                            AS DATA_FREE,
           #  0 AS `AUTO_INCREMENT`,
           if(relkind = 'v', NULL, internal_auto_increment(reldatabase, relname))                AS `AUTO_INCREMENT`,
           created_time                                                                          AS CREATE_TIME,
           if(relkind = 'v', NULL, created_time)                                                 AS UPDATE_TIME,
           if(relkind = 'v', NULL, created_time)                                                 AS CHECK_TIME,
           'utf8mb4_0900_ai_ci'                                                                  AS TABLE_COLLATION,
           if(relkind = 'v', NULL, 0)                                                            AS CHECKSUM,
           if(relkind = 'v', NULL, if(partitioned = 0, '', cast('partitioned' as varchar(256)))) AS CREATE_OPTIONS,
           cast(rel_comment as text)                                                             AS TABLE_COMMENT
    FROM mo_catalog.mo_tables tbl
    WHERE tbl.account_id = current_account_id()
      and tbl.relname not like '__mo_index_%'
      and tbl.relkind != 'partition'
    

    上面sql注释掉 AUTO_INCREMENT列能正常执行,看起来是internal_auto_increment的问题。

  3. added this to the 1.2.1 milestone on Jun 24, 2024
  4. ouyuanning commented on Jun 24, 2024

    @ouyuanning
    Contributor

    builtInInternalAutoIncrement 这个函数的 getCurrentValue 报的错。
    应该是proc.Ctx 的值不太对。锦赛有空的话可以先帮看看。

  5. ouyuanning commented on Jun 24, 2024

    @ouyuanning
    Contributor

    上面的分析不对。应该是启动的时候的问题。因为拿最新的main启动后, 一直回退到很久以前的PR都会有问题。
    但是如果拿很久以前的PR,自己启动,就不会有问题。

    刚二分了一下。是这个PR引入的
    #16787

    @qingxinhome 有空帮看看吧

  6. qingxinhome commented on Jun 25, 2024

    @qingxinhome
    Contributor

    分析结论如下:
    问题1:为什么视图会有自增列?这个和视图对应的查询语句的执行计划有关。

    如果定义如下包含自增列a的表t:
    create table t(
    a int unsigned auto_increment,
    b varchar(15),
    primary key(a)
    );

    基于t表定义一个视图v,
    create view v as select a from t;
    视图v中包含a列,其来自于t表的自增列a, 这个自增列的属性也被带到了视图v的tableDef定义中,

    在pr #15984 提交之前,mo内部对表和视图定义是放在一起处理的,在处理逻辑的末尾, 会登记relation的自增列信息, 如下图所示,
    a238724eaec3114be932165360effd4

    但是maybeCreateAutoIncrement函数,并未对表和视图做区分,导致一部分特殊的视图被当做含有自增列的表进行处理,我们早期一直都是这么做的,这个第一处bug, 该bug会把视图也存放到自增列表中。这个是存的问题,第二处bug是取数据的问题
    视图本不应该有自增列,但是在内部系统函数internal_auto_increment,取relation的自增列信息的时候, 并没有对表和视图作区分, 这是第二处bug, 两处bug形成闭环,所以之前一直没有暴露这个问题

    问题2: 为什么拆分后,查询information_schema.tables系统视图会报错?
    pr: https://github.com/matrixorigin/matrixone/pull/15984, 对是视图和表的定义执行做了拆分,视图与自增列无关,这个做法是正确的, 但是information_schema.tables系统视图中使用了内部系统函数internal_auto_increment, internal_auto_increment取自增列时没有区分视图和表,于是就报错[Bug]: Cannot find tableID 272437
    才导致该问题暴露出来,

  7. qingxinhome commented on Jun 26, 2024

    @qingxinhome
    Contributor

    The issue has been resolved, please verify and test @sukki37 @ouyuanning @aressu1985 @daviszhen @ck89119 @jensenojs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugphase/testingseverity/s-1

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions