当前位置:网站首页>GBase 8s查询处理和优化
GBase 8s查询处理和优化
2022-04-23 01:17:00 【八珍豆腐】
查询处理是指从数据库中提取数据时所涉及的一系列活动,包括:将高层数据库语言表示的查询语句翻译为可在文件系统的物理层上使用的表达方式、为优化查询进行的各种转换、以及查询的实际执行度。
语法分析
SQL编辑器接收SQL语句并生成相应的语法树然后读取字典信息进行语法验证,如果有错误则返回错误。
另外,如果该语句被多次执行,则可以根据SQL缓存信息,直接执行对应的可执行代码,不需要对此类SQL语句进行“翻译”,可以大大提高某些经常被执行的SQL语句的效率。为此,GBase 8s提供了SQL statement caching的机制,可以通过Onconfig参数文件的STMT_CACHE等参数进行该功能的开启、关闭及相关控制。为了更好地利用该功能,在开发应用程序调用SQL语句时,应尽量通过绑定变量的方式。因为只有完全相同的SQL语句才被匹配,简单理解为对SQL语句进行字符串的匹配以找到已执行的SQL语句。
语义检查
为了确保SQL语句的所有组成部分都符合要求,需要进行语义检查。举个简单的例子,时间类型字段传递的值需要满足时间格式的要求。例如select * from orders where order_date=’2015-5-12 10:00:00’,针对该SQL查询语句,需要验证’2015-5-12 10:00:00’是否满足当前数据库环境中对时间格式的设置要求。
SQL重写
由于某些提交给数据库的SQL语句存在明显的性能问题,所以SQL编译器只需进行简单的重写即可以达到更好的性能效果。
示例1.提升谓词
原SQL如下:
SELECT * FROM tab1
WHERE tab1.c1 = 10 and tab1.c2 =
(SELECT max (tab2.c2) FROM tab2 WHERE tab2.c1 = tab1.c1)
重写后的SQL如下:
SELECT * FROM tab1
WHERE tab1.c1 = 10 and tab1.c2 =
(SELECT max(tab2.c2) FROM tab2 WHERE tab2.c1 =10)
示例2.“扁平化子查询”
把子查询重写为表关联的方式,可以提高查询性能。
原SQL如下:
SELECT t1.c1
FROM t1
WHERE t1.c2 > ANY
(SELECT t2.c2 FROM t2 WHERE t2.c3 = t1.c3)
重写后的SQL如下:
SELECT t1.c1
FROM t1,t2
WHERE t2.c3 = t1.c3 and t2.c2 < t1.c2
示例3.IN转换为OR
在某些情况下,可以利用所有OR运算,将IN谓词转换为一组OR子句。
原SQL如下:
select * from orders
where order_num in(‘1001’,’1002’)
and order_date=’01/30/2015’
重写后SQL如下:
Select * from orders
where (order_num = ‘1001’ or order_num = ‘1002’)
and order_date = ‘01/30/2015’
优化器
如果选择的是基于代价的优化器模式,则需要读取相关统计信息,以确定最优的执行方案。对于多个索引情况及含有多表连接的情况,优化器需要确定索引的优先使用情况。表的扫描顺序,综合考虑执行路径的成本,最终选择一个最优的执行计划。据此,我们需要对发生数据变化的表及时执行update statistics,以保证优化器能依据有效的统计信息做出最佳的执行计划。
一旦选定了查询计划,即用该计划来执行查询并输出查询结果。
版权声明
本文为[八珍豆腐]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_57486087/article/details/124319999
边栏推荐
- Chapter 9 of C language programming (fifth edition of Tan Haoqiang) analysis and answer of exercises for users to establish their own data types
- [Ethernet switching security] - switch flow control / DHCP snooping / IP source guard
- What is tooljet and how about it—— Evaluation of low code development platform
- JD side: comment un thread enfant obtient - il la valeur de threadlocal du thread parent? Je suis couvert...
- Examples of branch and loop statements
- Is it difficult for girls to learn software testing?
- In depth analysis of disk cache mechanism and SSD write amplification under Linux
- 留给给5月的文章
- 光猫超级帐号密码,重置光猫获取超级帐号密码
- Live broadcast software | IPTV live broadcast software | TV live broadcast | tvplayer IPTV easyplayer | youwo live broadcast | customized development of super live broadcast software
猜你喜欢

Innovative practice of short video content understanding and generation technology in meituan
![[actf2020 freshman competition]](/img/0c/4c06112383c0b225c987a499b622a9.png)
[actf2020 freshman competition]

2022 penetration job interview (thinking)

Processus d'analyse et de configuration du matériel IIC pour le développement de la machine nue imx6ull

Source code analysis of synchronousqueue

Basic knowledge of software testing (detailed version) collection of this article is enough

API IX JWT auth plug-in has an error. Risk announcement of information disclosure in response (cve-2022-29266)

【蓝桥杯国赛真题18】Scratch加法选择题 青少年组 scratch蓝桥杯国赛真题和答案讲解

In depth report: in the heterogeneous era, chips need to integrate multiple templates

Acrel-2000型电力监控系统在兴庆坊新兴广场配电所配电回路用电的实时监控和管理
随机推荐
Good test data management, in the end how to do?
Detailed explanation of Milvus 2.0 quality assurance system
安全用电管理平台在靖边博物馆安全用电管理系统的应用
Open WebRTC Toolkit(OWT) Server User Guide
C language guessing game and trickery game
Error: permissionerror: [winerror 32] this file is in use by another program and cannot be accessed by the process. Solution of "+ file path"
Five commonly used order receiving platforms recommended by programmers
VS+C# 实现窗体输入框默认显示灰色文字
Get rid of the "small workshop" of AI production: how to build a cloud native AI platform based on kubernetes
Live broadcast software | IPTV live broadcast software | TV live broadcast | tvplayer IPTV easyplayer | youwo live broadcast | customized development of super live broadcast software
App中使用微信公众号的模版消息来进行消息推送
[Ethernet switching security] - switch flow control / DHCP snooping / IP source guard
【服务器数据恢复】服务器硬盘进水后服务器崩溃的数据恢复案例
【蓝桥杯国赛真题18】Scratch加法选择题 青少年组 scratch蓝桥杯国赛真题和答案讲解
From construction to governance, the industry's first white paper on microservice governance technology was officially released (including a free download link)
2022 penetration job interview (thinking)
Getting started with the go language is simple: the sortints method in sort
200. Number of islands
[JS] realize the export of PDF from the specified area of the web page
换个姿势看 hooks,灵感来源组合和 HOC 模式下逻辑视图分离新创意