KingbaseES where 条件解析顺序
2024-09-08 11:31:09
概述
KingbaseES 对于where 条件的解析严格遵守“从左到右”的原则,因此,对于选择性比较强的条件,进行最先过滤是有利于性能的。
一、KingbaseES
1、条件顺序影响执行效率
例子:
create table t1(id1 integer,id2 integer);
insert into t1 select generate_series(1,1000000),generate_series(1,1000000);
条件顺序影响性能:经 id1 过滤掉的数据更多,放在前面效率更优。
test=# explain analyze select * from t1 where id2>1000000 and id1>9999000;
QUERY PLAN
--------------------------------------------------------------------------------------------------------------
Seq Scan on t1 (cost=0.00..194248.72 rows=1111116 width=8) (actual time=815.263..815.350 rows=1000 loops=1)
Filter: ((id2 > 1000000) AND (id1 > 9999000))
Rows Removed by Filter: 9999000
Planning Time: 0.064 ms
Execution Time: 815.391 ms
(5 rows) test=# explain analyze select * from t1 where id1>9999000 and id2>1000000;
QUERY PLAN
----------------------------------------------------------------------------------------------------------
Seq Scan on t1 (cost=0.00..194247.65 rows=899 width=8) (actual time=747.644..747.733 rows=1000 loops=1)
Filter: ((id1 > 9999000) AND (id2 > 1000000))
Rows Removed by Filter: 9999000
Planning Time: 0.069 ms
Execution Time: 747.773 ms
(5 rows)
2、条件顺序影响SQL执行
例子:
create table t1(id1 varchar(10),id2 varchar(10));
insert into t1 values('123','abc'); test=# select * from t1 where id1=1 and id2=2;
id1 | id2
-----+-----
(0 rows) test=# select * from t1 where id2=2 and id1=1;
ERROR: invalid input syntax for type integer: "abc"
问题分析:这里的语句实际 是:select * from t1 where to_number(id1)=1 and to_number(id2)=2 。语句在执行时,先根据 to_number(id1)=1 条件进行过滤,只有满足to_number(id1)=1条件,才 过来 to_number(id2)=2 条件。
语句1:to_number(123)=1 不满足,因此,没必要执行 to_number(id2)=2 ,不会报错
语句2:先执行 to_number(id2)=2 ,直接报错了。
最新文章
- java 基础导航
- tomcat配置SSL双向认证
- laravel old
- HDU 5919 Sequence II(主席树+逆序思想)
- C#中TreeView与数据库绑定
- 循环列表的Java实现,解决约瑟夫环问题
- 【设计模式】学习笔记17:代理模式之保护代理与Java反射
- linux 配置Socks51
- js中eval函数
- ARM架构和编程-4
- Django: 之数据库导入、迁移和联用
- Host 'hello-PC' is not allowed to connect to this MySQL server远程连接mysql授权
- Maven 私服的简单使用
- [Luogu 1919]【模板】A*B Problem升级版(FFT快速傅里叶)
- C#3.0 Lamdba表达式与表达式树
- live 2d js demo
- 看CES 2017上有哪些好玩的物联网设备
- 【Android】详解Android动画之Interpolator插入器
- JVM内存模型、指令重排、内存屏障概念解析(转载)
- dubbo注册中心介绍
热门文章
- element ui 自定义主题失败(primordials is not defined)
- cve_2019_0708_bluekeep漏洞
- NC235250 牛可乐的翻转游戏
- js导入excel&;导出excel
- Mark IntelliJ IDEA 2018.2.3破解
- SQLZOO练习二--SELECT from Nobel Tutorial
- springboot 中如何正确在异步线程中使用request
- C#/VB.NET 添加多行文本水印到Word文档
- jdbc 01: 连接mysql,并实现数据插入
- BS架构与CS架构