Clickhouse 基础知识一(视图、Log家族、建表、临时表、分区DDL)

1、视图

a) 普通视图:不会存储数据
b) 物化视图:1、储存数据;2、有引擎,在磁盘存储;3、同步映射表数据

2、表引擎Log系列

       4.1 TinyLog
                1、最简单的引擎
                2没有索引,没有标记块
                3写是追加写
                4、数据以列字段文件存储
                5不允许同时读写
                
                
            4.2 StripeLog
                1、data.bin存储所有数据
                2、index.mrk对数据建立索引
                3、size.json 数据大小
                4并发读写
                
            4.3 Log
                1、*.bin存储每个字段的数据
                2、mark.mrk 数据块标记
                3、支持多线程处理
                4、并发读写

3、普通建表

        create table : default(默认字段)、comment(字段注释)、默认是UTF8
        
        跨数据库复制表结构: create table as databaseName.tableName
        
        跨数据库复制表结构和数据: create table engine=xxx as select * from tableName

4、临时表

        create temporary table log  as select * from databaseName.tableName
        1、不属于任何数据库,不需要指定引擎
        2、会话断开以后表删除、不会持久化
        3、如果本地表和临时表冲突,临时表优先
        4、作用:数据库之间的数据迁移

5、分区表DDL

        1、创建分区表 create table ....... partition by columnName
        
        2查看分区内容: select partition ,name ,table  from system.parts where ....
        
        3、删除分区:alter table drop partition ""  
        4、修改分区:alter table tableName replace partition "" from b 
        5、清除分区中的某个字段的值:alter table tableName clear columnName id in partition
        6、卸载分区数据detach: alter table account detach partition 'AA'
        7、装载分区数据attach: alter table account attach partition 'AA'

6、DDL修改表结构

        1、添加字段:alter table tableName add column  columnName  type 
        2、删除字段:alter table tableName drop column columnName type 
        3、修改字段:alter table tableName modify column columnName type
        4、增加注释:alter table tableName comment columnName '注释'
        5、移动表|重命名: rename table a to b
                           rename table a to newdb.a
                           rename table a to newdb.b
原文地址:https://www.cnblogs.com/ywjfx/p/14324835.html