计算
弹性云服务器 ECS
Flexus云服务
裸金属服务器 BMS
弹性伸缩 AS
镜像服务 IMS
专属主机 DeH
函数工作流 FunctionGraph
云手机服务器 CPH
Huawei Cloud EulerOS
网络
虚拟私有云 VPC
弹性公网IP EIP
虚拟专用网络 VPN
弹性负载均衡 ELB
NAT网关 NAT
云专线 DC
VPC终端节点 VPCEP
云连接 CC
企业路由器 ER
企业交换机 ESW
全球加速 GA
安全与合规
安全技术与应用
Web应用防火墙 WAF
企业主机安全 HSS
云防火墙 CFW
安全云脑 SecMaster
DDoS防护 AAD
数据加密服务 DEW
数据库安全服务 DBSS
云堡垒机 CBH
数据安全中心 DSC
云证书管理服务 CCM
边缘安全 EdgeSec
威胁检测服务 MTD
CDN与智能边缘
内容分发网络 CDN
CloudPond云服务
智能边缘云 IEC
迁移
主机迁移服务 SMS
对象存储迁移服务 OMS
云数据迁移 CDM
迁移中心 MGC
大数据
MapReduce服务 MRS
数据湖探索 DLI
表格存储服务 CloudTable
云搜索服务 CSS
数据接入服务 DIS
数据仓库服务 GaussDB(DWS)
数据治理中心 DataArts Studio
数据可视化 DLV
数据湖工厂 DLF
湖仓构建 LakeFormation
企业应用
云桌面 Workspace
应用与数据集成平台 ROMA Connect
云解析服务 DNS
专属云
专属计算集群 DCC
IoT物联网
IoT物联网
设备接入 IoTDA
智能边缘平台 IEF
用户服务
账号中心
费用中心
成本中心
资源中心
企业管理
工单管理
国际站常见问题
ICP备案
我的凭证
支持计划
客户运营能力
合作伙伴支持计划
专业服务
区块链
区块链服务 BCS
Web3节点引擎服务 NES
解决方案
SAP
高性能计算 HPC
视频
视频直播 Live
视频点播 VOD
媒体处理 MPC
实时音视频 SparkRTC
数字内容生产线 MetaStudio
存储
对象存储服务 OBS
云硬盘 EVS
云备份 CBR
存储容灾服务 SDRS
高性能弹性文件服务 SFS Turbo
弹性文件服务 SFS
云硬盘备份 VBS
云服务器备份 CSBS
数据快递服务 DES
专属分布式存储服务 DSS
容器
云容器引擎 CCE
容器镜像服务 SWR
应用服务网格 ASM
华为云UCS
云容器实例 CCI
管理与监管
云监控服务 CES
统一身份认证服务 IAM
资源编排服务 RFS
云审计服务 CTS
标签管理服务 TMS
云日志服务 LTS
配置审计 Config
资源访问管理 RAM
消息通知服务 SMN
应用运维管理 AOM
应用性能管理 APM
组织 Organizations
优化顾问 OA
IAM 身份中心
云运维中心 COC
资源治理中心 RGC
应用身份管理服务 OneAccess
数据库
云数据库 RDS
文档数据库服务 DDS
数据管理服务 DAS
数据复制服务 DRS
云数据库 GeminiDB
云数据库 GaussDB
分布式数据库中间件 DDM
数据库和应用迁移 UGO
云数据库 TaurusDB
人工智能
人脸识别服务 FRS
图引擎服务 GES
图像识别 Image
内容审核 Moderation
文字识别 OCR
AI开发平台ModelArts
图像搜索 ImageSearch
对话机器人服务 CBS
华为HiLens
视频智能分析服务 VIAS
语音交互服务 SIS
应用中间件
分布式缓存服务 DCS
API网关 APIG
微服务引擎 CSE
分布式消息服务Kafka版
分布式消息服务RabbitMQ版
分布式消息服务RocketMQ版
多活高可用服务 MAS
事件网格 EG
企业协同
华为云会议 Meeting
云通信
消息&短信 MSGSMS
云生态
合作伙伴中心
云商店
开发者工具
SDK开发指南
API签名指南
Terraform
华为云命令行工具服务 KooCLI
其他
产品价格详情
系统权限
管理控制台
客户关联华为云合作伙伴须知
消息中心
公共问题
开发与运维
应用管理与运维平台 ServiceStage
软件开发生产线 CodeArts
需求管理 CodeArts Req
部署 CodeArts Deploy
性能测试 CodeArts PerfTest
编译构建 CodeArts Build
流水线 CodeArts Pipeline
制品仓库 CodeArts Artifact
测试计划 CodeArts TestPlan
代码检查 CodeArts Check
代码托管 CodeArts Repo
云应用引擎 CAE
开天aPaaS
云消息服务 KooMessage
云手机服务 KooPhone
云空间服务 KooDrive

配置物化视图改写能力

更新时间:2024-11-29 GMT+08:00

开启物化视图改写能力

HetuEngine支持在System级别或者Session级别开启物化视图改写能力,开启方法如下所示:

  • Session级别:

    参考使用HetuEngine客户端HetuEngine客户端执行set session materialized_view_rewrite_enabled=true

  • System级别:
    1. 使用用于访问HetuEngine WebUI界面的用户登录FusionInsight Manager。
    2. 选择“集群 > 服务 > HetuEngine”,进入HetuEngine服务页面。
    3. 在概览页签下的“基本信息”区域单击“HSConsole WebUI”后的链接,进入HSConsole界面。
    4. 单击“计算实例”,查看待操作的租户的实例状态,当绿色图标和蓝色图标数量均为“0”时,可执行5配置开启物化视图改写能力。
    5. 在“计算实例”页签,在待操作的实例所属租户所在行的“操作”列单击“配置”,进入“配置实例”页签,添加如下自定义参数。

      名称

      参数文件

      materialized.view.rewrite.enabled

      true

      coordinator.config.properties

      materialized.view.rewrite.timeout

      5

      coordinator.config.properties

      说明:
      • materialized.view.rewrite.timeout:物化视图的重写超时控制(单位:秒),推荐5s。物化视图重写时会消耗一定的时间,添加该参数可限制重写所带来的性能损耗,物化视图重写超时后会执行原始SQL。
      • 若使用Session级别开启物化视图功能,并需要开启物化视图重写超时控制,可先执行set session materialized_view_rewrite_timeout = 5
    6. 参数添加完成后, 将“立即启动”置为“是”,单击“确定”。

物化视图改写能力支持范围

  • 物化视图支持的类型

    BOOLEAN、DECIMAL、DOUBLE、REAL/FLOAT、INT、BIGINT、SMALLINT、TINYINT、CHAR/VARCHAR、DATE、TIME、TIMESTAMP、INTERVAL YEAR TO MONTH、INTERVAL DAY TO SECOND、BINARY/VARBINARY、UUID。

  • 物化视图改写支持的函数
    • 转换函数:只支持CAST函数。
    • 字符串函数:支持所有字符串函数,包括char_length、character_length、chr、codepoint、decode、encode、find_in_set、format_number、locate、hamming_distance、instr、levenshtein、levenshtein_distance、ltrim、lpad、octet_length、position、quote、repeat2。
    • 数学运算符:支持所有数学运算符。
    • 聚合函数:支持的聚合函数包括 COUNT、SUM、MIN、MAX、AVG、LEAD、LAG、FIRST_VALUE、LAST_VALUE、COVAR_POP、COVAR_SAMP、REGR_SXX、REGR_SYY、STDDEV_POP、STDDEV_SAMP、VAR_POP、VAR_SAMP、ROW_NUMBER、RANK、PERCENT_RANK、DENSE_RANK、CUME_DIST。
    须知:

    以下场景,物化视图不支持对包含了函数的SQL查询进行改写:

    • SQL中包含无参函数
    • SQL中包含了HetuEngine支持的会根据参数的类型获得不同类型的返回值的函数
    • SQL中函数存在嵌套使用,或者是使用的函数会发生异常导致重写失败的函数

物化视图改写场景示例

物化视图的改写的核心原理是逻辑上创建的物化视图的数据要包含未来的查询语句要查询的数据,也可以是未来查询中的子查询要包含的全部数据。建议用户打开自动创建物化视图功能针对性的创建物化视图,以下为部分场景示例:

创建物化视图SQL样例中省略“CREATE MATERIALIZED VIEW xxx WITH(xxx) AS”,完整语句模板可参考表1

表1 物化视图改写场景示例

场景

描述

创建物化视图SQL样例

用户查询SQL样例

查询SQL是否能被改写

备注

全表查询

最基本的全表查询场景

select * from tb_a;

select * from tb_a;

创建全表扫描的物化视图没有实际意义,不支持

列查询

最基本的列查询场景

select col1,col2,col3 from tb_a;

select col1,col2,col3 from tb_a;

-

用户查询重命名

select col1 from tb_a;

select col1 as a from tb_a;

-

select col1,col2,col3 from tb_a;

select col1 as a,col2 as b,col3 as c from tb_a;

-

数学表达式

select col1*col2 from tb_a;

select col2*col1 from tb_a;

需要两个列的类型一样

物化视图使用源列,用户查询使用cast

select col1,col2 from tb_a;

select cast(col1 as varchar),col2 from tb_a;

物化视图使用原数据列,用户查询使用函数没有过滤条件不改写

物化视图使用原数据列,用户查询也是用原数据列加过滤条件可改写

case when场景

select col1, (case col2 when 1 then 'b' when 2 'a' end) as col from tb_a;

select col1, (case col2 when 1 then 'b' when 2 'a' end) as col from tb_a;

不支持查询列中出现case when场景

字符串函数

select col13 from tb_a;

select length(col13) from tb_a;

所有的字符串函数用原表数据建立物化视图不加过滤条件的查询做物化视图不会改写

select length(col13) from tb_a;

select length(col13) from tb_a;

-

聚合函数列查询

count

物化视图和用户查询一样使用count

select count(col1) from tb_a;

select count(col1) from tb_a;

-

物化视图使用源数据,用户查询使用count

select col1 from tb_a;

select count(col1) from tb_a;

-

sum

物化视图和用户查询一样使用sum

select sum(col1) from tb_a;

select sum(col1) from tb_a;

-

物化视图使用源数据,用户查询使用sum

select col1 from tb_a;

select sum(col1) from tb_a;

-

过滤查询

(核心在于物化视图的数据逻辑上要比查询SQL相同或者更多)

where过滤

物化视图最大范围(<)

select col1 from tb_a;

select col1 from tb_a where col1<11;

-

物化视图范围大于用户查询范围(<)

select col1 from tb_a where col1<50;

select col1 from tb_a where col1<45;

-

select col1 from tb_a where col1<50;

select col1 from tb_a where col1<=45;

-

select col1 from tb_a where col1<50;

select col1 from tb_a where col1 between 21 and 29;

-

物化视图范围等于用户查询范围(>)

select col1 from tb_a where col1<50;

select col1 from tb_a where col1<50;

-

物化视图范围大于用户查询范围(and)

select col1 from tb_a where col1<60 and col1>30;

select col1 from tb_a where col1<55 and col1>30;

-

select col1 from tb_a where col1<60 and col1>30;

select col1 from tb_a where col1 between 35 and 55;

-

select col1 from tb_a where col1<60 and col1>30;

select col1 from tb_a where (col1<55 and col1>30) and col1 = 56;

-

where嵌套子查询

子查询源表做物化视图

select col1 from tb_a;

select count(col1) from tb_a where col1=(select min(col1) from tb_a);

-

子查询做物化视图

select min(col1) from tb_a;

select count(col1) from tb_a where col1=(select min(col1) from tb_a);

-

父查询源表做物化视图

select col1 from tb_a where col1=(select min(col1) from tb_a);

select count(col1) from tb_a where col1=(select min(col1) from tb_a);

-

父查询做物化视图

select count(col1) from tb_a where col1=(select min(col1) from tb_a);

select count(col1) from tb_a where col1=(select min(col1) from tb_a);

-

limit

limit在查询里

select col1 from tb_a;

select col1 from tb_a limit 5;

-

select col1 from tb_a limit 5;

select col1 from tb_a limit 5;

-

select col1 from tb_a limit 5;

select col1 from tb_a;

-

limit结合order by

select col1 from tb_a;

select col1 from tb_a order by col1 limit 5;

创建物化视图时使用order by可能导致改写后结果无序,如果开启物化视图改写功能,查询SQL中有order by和limit,建议创建物化视图SQL去掉limit和order by

select col1 from tb_a order by col1;

select col1 from tb_a order by col1 limit 5;

select col1 from tb_a order by col1 limit 5;

select col1 from tb_a order by col1 limit 5;

having过滤

物化视图最大范围(<)

select col1 from tb_a;

select col1 from tb_a group by col1 having col1 <11;

group by + having:having的场景和where不一样,having的条件无法做到补偿,要求物化视图SQL的没有having条件或者与用户查询SQL的having条件一致

物化视图范围大于用户查询范围(<)

select col1 from tb_a group by col1 having col1<50;

select col1 from tb_a group by col1 having col1<45;

select col1 from tb_a group by col1 having col1<50;

select col1 from tb_a group by col1 having col1<=45;

select col1 from tb_a group by col1 having col1<50;

select col1 from tb_a group by col1 having col1=45;

select col1 from tb_a group by col1 having col1<50;

select col1 from tb_a group by col1 having col1 between 21 and 29;

物化视图范围等于用户查询范围(<)

select col1 from tb_a group by col1 having col1<50;

select col1 from tb_a group by col1 having col1<50;

JOIN关联查询

两个子查询做物化视图

select col1,col3 from tb_a where col1<11;

with t1 as (select col1,col3 from tb_a where col1<11),t2 as (select cast(col2 as varchar) col2,col3 from tb_b) select col1,col2 from t1 join t2 on t1.col3=t2.col3;

-

select cast(col2 as varchar) col2,col3 from tb_b;

with t1 as (select col1,col3 from tb_a where col1<11),t2 as (select cast(col2 as varchar) col2,col3 from tb_b) select col1,col2 from t1 join t2 on t1.col3=t2.col3;

-

父查询做物化视图

with t1 as (select col1,col3 from tb_a),t2 as (select col2,col3 from tb_b) select col1,col2 from t1 join t2 on t1.col3=t2.col3;

with t1 as (select col1,col3 from tb_a where col1<11),t2 as (select cast(col2 as varchar) col2,col3 from tb_b) select col1,col2 from t1 join t2 on t1.col3=t2.col3;

-

聚合+JOIN查询

源表数据做物化视图

select col1,col3 from tb_a;

with t1 as (select col1,col3 from tb_a where col1<11),t2 as (select cast(col2 as varchar) col2,col3 from tb_b) select count(col1) from t1 join t2 on t1.col3=t2.col3;

-

select col2,col3 from tb_b;

with t1 as (select col1,col3 from tb_a where col1<11),t2 as (select cast(col2 as varchar) col2,col3 from tb_b) select count(col1) from t1 join t2 on t1.col3=t2.col3;

-

子查询做物化视图

select col1,col3 from tb_a where col1<11;

with t1 as (select col1,col3 from tb_a where col1<11),t2 as (select cast(col2 as varchar) col2,col3 from tb_b) select count(col1) from t1 join t2 on t1.col3=t2.col3;

-

select cast(col2 as varchar) col2,col3 from tb_b;

with t1 as (select col1,col3 from tb_a where col1<11),t2 as (select cast(col2 as varchar) col2,col3 from tb_b) select count(col1) from t1 join t2 on t1.col3=t2.col3;

-

子查询使用源表的父查询(非聚合查询)做物化视图

with t1 as (select col1,col3 from tb_a),t2 as (select col2,col3 from tb_b) select col1,col2 from t1 join t2 on t1.col3=t2.col3;

with t1 as (select col1,col3 from tb_a where col1<11),t2 as (select cast(col2 as varchar) col2,col3 from tb_b) select count(col1) from t1 join t2 on t1.col3=t2.col3;

-

父查询(非聚合查询)做物化视图

with t1 as (select col1,col3 from tb_a where col1<11),t2 as (select cast(col2 as varchar) col2,col3 from tb_b) select col1,col2 from t1 join t2 on t1.col3=t2.col3;

with t1 as (select col1,col3 from tb_a where col1<11),t2 as (select cast(col2 as varchar) col2,col3 from tb_b) select count(col1) from t1 join t2 on t1.col3=t2.col3;

-

父查询做物化视图

with t1 as (select col1,col3 from tb_a where col1<11),t2 as (select cast(col2 as varchar) col2,col3 from tb_b) select count(col1) from t1 join t2 on t1.col3=t2.col3;

with t1 as (select col1,col3 from tb_a where col1<11),t2 as (select cast(col2 as varchar) col2,col3 from tb_b) select count(col1) from t1 join t2 on t1.col3=t2.col3;

-

我们使用cookie来确保您的高速浏览体验。继续浏览本站,即表示您同意我们使用cookie。 详情

文档反馈

文档反馈

意见反馈

0/500

标记内容

同时提交标记内容