1. 创建Duplicate表:
CREATE TABLE `wangdi_log_test` ( `op_time` DATETIME NULL COMMENT ''请求时间'', `op_api` VARCHAR(255) NULL COMMENT ''请求API地址'', `op_ip` VARCHAR(64) NULL COMMENT ''请求ip'', `id` BIGINT NOT NULL COMMENT ''主键id'', `op_application` VARCHAR(128) NULL COMMENT ''APP名称'', `op_category` VARCHAR(128) NULL COMMENT ''业务分类'', `op_module` VARCHAR(128) NULL COMMENT ''模块名称'', `op_func` VARCHAR(128) NULL COMMENT ''功能名称'', `op_code` VARCHAR(128) NULL COMMENT ''功能子项代码'', `op_user` BIGINT NULL COMMENT ''操作人'', `op_action` VARCHAR(32) NULL COMMENT ''操作类型'', `op_status` VARCHAR(16) NULL COMMENT ''状态'', `op_error_msg` VARCHAR(255) NULL COMMENT ''错误信息'', `op_primary_key` BIGINT NULL COMMENT ''操作对象主键'', `op_primary_name` VARCHAR(255) NULL COMMENT ''对象名称'', `op_end_time` DATETIME NULL COMMENT ''操作完成时间'' ) ENGINE=OLAP DUPLICATE KEY(`op_time`, `op_api`) COMMENT 'OLAP' DISTRIBUTED BY HASH(`op_api`) BUCKETS 1 PROPERTIES ( "replication_allocation" = "tag.location.default: 1", "min_load_replica_num" = "-1", "is_being_synced" = "false", "storage_format" = "V2", "compression" = "ZSTD", "light_schema_change" = "true", "compaction_policy" = "time_series", "time_series_compaction_goal_size_mbytes" = "1024", "time_series_compaction_file_count_threshold" = "2000", "time_series_compaction_time_threshold_seconds" = "3600", "disable_auto_compaction" = "false", "enable_single_replica_compaction" = "true", "group_commit_interval_ms" = "10000" );
2. 创建物化视图:
create materialized view wangdi_log_test_op_ip
as
select op_ip, count(0) from wangdi_log_test group by op_ip
3. explain查询计划:
EXPLAIN select op_ip, count(0) from wangdi_log_test group by op_ip
4. 结果如下: