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

Redesign partition view #10996

Closed

Conversation

qingxinhome
Copy link
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #10281

What this PR does / why we need it:

为了更方便的查询和分析mo的分区表,以及支持兼容mysql的navicat工具,本PR实现了如下主要功能

  1. 在mo_catalog下新增一个元数据表mo_table_partitions,用于存放分区表详细的分区信息
    具体细节如下:

  2. 在mo_catalog下新增一个元数据表mo_table_partitions,用于存放分区表详细的分区信息
    -> table_id :
    当前分区表的ID。
    -> database_id :
    当前分区表所属的数据库的ID。
    -> number :
    当前分区编号,所有分区都按照定义的顺序进行索引,其中1是分配给第一个分区的数字。索引可以随着分区的添加、删除和重新组织而更改;
    显示的数字是,此列反映当前顺序,并考虑了任何索引更改。
    -> name :
    分区的名称
    ->partition_type
    存放表的分区类型信息,如果是分区表,其值枚举为"KEY", "LINEAR_KEY","HASH", "LINEAR_KEY_51", "RANGE", "RANGE_COLUMNS", "LIST", "LIST_COLUMNS",
    如果不是分区表,partition_type的值为空字符串
    ->partition_expression
    创建分区表的的CREATE TABLE或ALTER TABLE语句中使用的分区函数的表达式。例如,考虑使用以下语句在测试数据库中创建的分区表:
    CREATE TABLE tp (
    c1 INT,
    c2 INT,
    c3 VARCHAR(25)
    )
    PARTITION BY HASH(c1 + c2)
    PARTITIONS 4;

    此表中分区的PARTITIONS_EXPRESSION表行中的PARTITION _EXPRESSION列显示c1+c2
    -> description_utf8 :
    此列用于RANGE和LIST分区。对于RANGE分区,它包含分区的VALUES LESS THAN子句中设置的值,该值可以是整数或MAXVALUE。对于LIST分区,此列包含分区的values in子句中定义的值,该子句是逗号分隔的整数值列表。
    对于不是RANGE或LIST的分区,此列始终为NULL。
    -> comment :
    注释的文本(如果分区有注释的话)。否则,此值为空。
    -> options :
    分区的选项信息,暂时为NULL
    -> partition_table_name :
    当前分区对应的分区子表名字

  3. 在information_schema下新增一个系统视图PARTITIONS,以兼容mysql的information_schema.PARTITIONS系统视图
    PARTITIONS表提供了有关表分区的信息。该表中的每一行都对应于分区表的一个单独分区或子分区。
    有关分区表的更多信息,请参阅MYSQL官网链接:https://dev.mysql.com/doc/refman/8.0/en/information-schema-partitions-table.html
    该视图的定义如下:
    CREATE VIEW PARTITIONS AS
    SELECT
    'def' AS TABLE_CATALOG,
    tbl.reldatabase AS TABLE_SCHEMA,
    tbl.relname AS TABLE_NAME,
    part.name AS PARTITION_NAME,
    NULL AS SUBPARTITION_NAME,
    part.number AS PARTITION_ORDINAL_POSITION,
    NULL AS SUBPARTITION_ORDINAL_POSITION,
    (case part.partition_type when 'HASH' then 'HASH' when 'RANGE' then 'RANGE' when 'LIST' then 'LIST' when 'AUTO' then 'AUTO' when 'KEY_51' then 'KEY' when 'KEY_55' then 'KEY' when 'LINEAR_KEY_51' then 'LINEAR KEY' when 'LINEAR_KEY_55' then 'LINEAR KEY' when 'LINEAR_HASH' then 'LINEAR HASH' when 'RANGE_COLUMNS' then 'RANGE COLUMNS' when 'LIST_COLUMNS' then 'LIST COLUMNS' else NULL end) AS PARTITION_METHOD,
    NULL AS SUBPARTITION_METHOD,
    part.partition_expression AS PARTITION_EXPRESSION,
    NULL AS SUBPARTITION_EXPRESSION,
    part.description_utf8 AS PARTITION_DESCRIPTION,
    mo_table_rows(tbl.reldatabase, part.partition_table_name) AS TABLE_ROWS,
    0 AS AVG_ROW_LENGTH,
    0 AS DATA_LENGTH,
    0 AS MAX_DATA_LENGTH,
    0 AS INDEX_LENGTH,
    0 AS DATA_FREE,
    tbl.created_time AS CREATE_TIME,
    NULL AS UPDATE_TIME,
    NULL AS CHECK_TIME,
    NULL AS CHECKSUM,
    ifnull(part.comment,'') AS PARTITION_COMMENT,
    'default' AS NODEGROUP,
    NULL AS TABLESPACE_NAME
    FROM mo_catalog.mo_tables tbl LEFT JOIN mo_catalog.mo_table_partitions part
    ON part.table_id = tbl.rel_id
    WHERE tbl.partitioned = 1;

@qingxinhome qingxinhome closed this Aug 5, 2023
@qingxinhome qingxinhome reopened this Aug 5, 2023
@qingxinhome qingxinhome closed this Aug 5, 2023
@qingxinhome qingxinhome deleted the RedesignPartitionView branch August 15, 2023 01:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature size/L Denotes a PR that changes [500,999] lines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants