【问题标题】:Mysql getting ready to do 2014 monthly partitionsmysql准备做2014年月度分区
【发布时间】:2013-11-19 17:36:08
【问题描述】:

我需要获取 2014 年尚未分区的所有表的数据库和表的列表。 我正在考虑查询满足以下条件的information_schema.PARTITIONS

PARTITION_NAME IS NOT NULL
PARTITION_NAME='p201312'
AND PARTITION_NAME !='p201401'

我怎么能查询这个。我试过了:

select DISTINCT * FROM(select `TABLE_SCHEMA`, `TABLE_NAME` from `information_schema`.`PARTITIONS` where PARTITION_NAME IS NOT NULL AND PARTITION_NAME='p201312' AND PARTITION_NAME!='p201401') as a;

但不起作用。请帮忙。

* 更新**

我能够汇总一个查询来获得我需要的内容:

SELECT a.TABLE_SCHEMA, a.TABLE_NAME FROM(从 information_schema.PARTITIONS 中选择 TABLE_SCHEMA, TABLE_NAME,其中 PARTITION_NAME='p201312')作为 左连接(从information_schema.PARTITIONS 中选择TABLE_SCHEMATABLE_NAME,其中 PARTITION_NAME='p201401')作为 b ON a.TABLE_NAME = b.TABLE_NAME 其中 b.TABLE_NAME 为空;

有没有办法让这个查询更优雅一点??

【问题讨论】:

  • 没有错误,但仍显示 PARTITION_NAME 为 p201401 的表
  • 我只需要分区到 2013 年的表 (p201312)
  • 使用子查询有什么意义?
  • 我需要查询所有具有像 p201312 但不像 p201401 这样的分区的表。所以我试图从 information_schema 中选择 TABLE_SCHEMATABLE_NAME
  • 但为什么不直接说select distinct table_schema, table_name from information_schema.partitions where ... 而不是select distinct * from (subquery)

标签: mysql sql partitioning information-schema


【解决方案1】:
select 
    table_schema, 
    table_name 
from 
    information_schema.tables t
where 
    not exists (
        select 
            null 
        from 
            information_schema.partitions p 
        where 
            p.table_schema = t.table_schema and 
            p.table_name = t.table_name and 
            p.partition_name like 'p2014%'
        )

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-01
    • 2015-11-02
    • 2014-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-21
    相关资源
    最近更新 更多