- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我很好奇多列索引的前导列的概念。
我正在使用这个示例 dvdrental分贝。
这是查询:
SELECT
title,
length,
rating,
replacement_cost,
rental_rate
FROM film
WHERE length BETWEEN 60 AND 70
AND rating = 'G';
我有两个正在使用的索引:
#1
CREATE INDEX IF NOT EXISTS film_idx_length_rating
ON film(length, rating);
#2
CREATE INDEX IF NOT EXISTS film_idx_rating_length
ON film(rating, length);
在创建两个索引后,计划者选择索引进行计划:
QUERY PLAN
Bitmap Heap Scan on film (cost=4.47..39.34 rows=15 width=34) (actual time=0.020..0.033 rows=18 loops=1)
Recheck Cond: ((rating = 'G'::mpaa_rating) AND (length >= 60) AND (length <= 70))
Heap Blocks: exact=14
-> Bitmap Index Scan on film_idx_rating_length (cost=0.00..4.46 rows=15 width=0) (actual time=0.015..0.015 rows=18 loops=1)
Index Cond: ((rating = 'G'::mpaa_rating) AND (length >= 60) AND (length <= 70))
Planning Time: 0.202 ms
Execution Time: 0.065 ms
执行了查询计划EXPLAIN ANALYZE
,规划器选择了第二个查询,但是来自两个索引的查询计划实际上并没有任何显着差异,只有规划器选择的索引。这是为什么?为什么当 rating
用作前导列时,它被选中而不是 length
作为前导列?
来自docs有这个:
A multicolumn B-tree index can be used with query conditions that involve any subset of the index's columns, but the index is most efficient when there are constraints on the leading (leftmost) columns. The exact rule is that equality constraints on leading columns, plus any inequality constraints on the first column that does not have an equality constraint, will be used to limit the portion of the index that is scanned.
但是我不是很明白,也许有人可以给我举个例子?
谢谢!
最佳答案
在您开始看到有意义的差异之前,您可能需要使表格比该链接处的表格大几千倍。
对于以相等列开头的索引,可以跳转到索引内的'G'段,然后可以跳到60的长度,向前读,直到超过70,所有这些行都会满足两种资格。
但是对于另外一个索引,不能直接跳到60,然后跳到G段,因为没有单独的G段。 60 到 70 之间的每个不同值都有一个 G 部分。所以它最终要做的是扫描从 60 到 70 的所有行,单独过滤掉不是 G 的行。
事实证明差别并不大,因为大部分时间都花在了访问表堆以从表中获取所需的数据上,在这种情况下,需要为任一索引访问同一组行。
关于postgresql - Postgres - 多列索引 - 前导(最左边)列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64196836/
我目前有以下选择语句: SELECT CONCAT(TRUNCATE(HOUR("215:00:36")/24,0),":",HOUR("215:00:36")%24,":",MINUTE("215:
我正在尝试将字符串编码为 base36。 static char *decode(unsigned long long value) { char base36[37] = "01234567
如果我有一个输入字符串,input 有三个或更多小数位,我希望该字符串由单独的 if-loop 处理。 我为此目的创建了以下控制台程序,如果(第一个约束)有小数点 .,则输入 if-loop字符串和(
我有一小段代码,它有一个整数数组,其中包含一些前导 0 的元素。 int arr[]={012,234,071}; cout<
如何从强制范围中删除前导,以便 Some field Any 1 2 3 « 最佳答案 删除 vertical-align: middle 后我觉得不错。 .mandato
我有这个 psd 并试图将它转换为 html css。 但是我无法从psd中计算出css中的行高。 如何根据前导+字体大小计算行高? 谢谢 最佳答案 如果行距不是自动的:LineHeight = fo
有谁知道如何更改文本字段上的行高(行距),最好是在 Interface Builder 中? 我已经找了大约一个小时了,但没有找到。 最佳答案 解决方法如下: Resizing NSTextField
是否可以在 C# 中的单元格元素(行)之间添加空格?我正在 Visual Studio 2012 中创建 pdf,并希望在行之间设置一些空间。我有这样的东西: PdfPTable cellTable
是否可以在 C# 中的单元格(行)元素之间添加空格?我正在 visual studio 2012 中创建一个 pdf,并希望在行之间设置一些空间。我有这样的东西: PdfPTable cellTabl
type ApplyFunc func(commitIndex uint64, cmd []byte) []byte 对于这个声明。我的理解是,这是一个函数指针。它的名字是 ApplyFunc。并且此
我很好奇多列索引的前导列的概念。 我正在使用这个示例 dvdrental分贝。 这是查询: SELECT title, length, rating, replacement_cost
我想将一个 double 格式格式化为最大长度为7的字符串,其中包含一个点“.”以及其后一位数字。 例如: 123.4 becomes "00123.4" 12345 becomes "12345
我需要正则表达式的帮助来从字符串中去除不需要的字符(在 Java 中)。我用 4 个正则表达式解决了这个问题。替换将被多次调用 [peeks: 50+ times/sec] 它并降低性能。但我认为它肯
只是将两个值连接到 mysql 表中的一列。 mysql 表中的第一个值和 PHP 常量中的第二个值保存为 define('ACCOUNTCODESUFFIX','016');。 MySql 查询有点
我如何按此顺序返回这些: 1: aaaa 2: bbbb 3: the cccc 4: dddd 所以忽略开头的“the” 目前我正在使用。 select * from houses order by
我通常使用以下代码将 PHP 变量导入 JavaScript: echo("var zipCode = " . $zipCode . ";"); 这工作正常,但对于以 0 开头的邮政编码,它会被 ch
有什么方法可以用前导 0 和小数来格式化 NSNumber 吗?例如,我需要有能力写 4.5 和 000。目前我有它允许小数,但不允许前导 0。 NSNumberFormatter *f = [[NS
你好我正在以编程方式创建标签栏,在我的功能中需要选择填充自定义颜色的标签,到目前为止我已经使用下面的代码实现了这一点,下面的输出见截图。 tabBarController.tabBar.selecti
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: Integer with leading zeroes 有人能告诉我这是怎么回事吗?当我用前导零初始化一个
在 Xcode 6 中,我可以使用编辑器菜单来固定: 引领空间至超视 到 Superview 的尾随空间 顶部空间到Superview Superview的底部空间 我找不到在 Xcode 7 bet
我是一名优秀的程序员,十分优秀!