我必须编写一个简单的查询,在其中查找以 B 或 D 开头的人名:
SELECT s.name
FROM spelers s
WHERE s.name LIKE 'B%' OR s.name LIKE 'D%'
ORDER BY 1
Run Code Online (Sandbox Code Playgroud)
我想知道是否有办法重写它以提高性能。所以我可以避免or和/或like?
postgresql index regular-expression pattern-matching string-searching
我只知道一点 sql 基础知识,需要编写一个简单的 sql 语法荧光笔/检查器所以我正在努力通过标准......我偶然发现了一些我不确定我是否理解正确的东西,因为我从未见过有人使用一个SET以这种方式。
它的定义如下所示:
<multiple column assignment> ::=
<set target list> <equals operator> <assigned row>
Run Code Online (Sandbox Code Playgroud)
以这种方式定义设置目标列表的地方:
<set target list> ::=
<left paren> <set target> [ { <comma> <set target> }... ] <right paren>
Run Code Online (Sandbox Code Playgroud)
这对我来说听起来是可以做到的:
UPDATE ...
SET (A, B, C) = (1, 2, 3)
Run Code Online (Sandbox Code Playgroud)
将 A 的值更新为 1,B 的值更新为 2,C 的值更新为 3。
我让反刍的是=因为我从来没有见过这样的 SET 并且在网上找不到任何使用这种方式的例子。
所以我也不确定是否正确理解整个定义。
有人能告诉我这是正确的吗?如果不是这样,你能解释一下这个定义的其他定义吗?
我的系统中有一个非常重要的查询,由于表上的数据量很大,执行时间太长。我是一名初级 DBA,我需要为此进行最佳优化。每个表大约有 8000 万行。
表是:
tb_pd:
Column | Type | Modifiers | Storage | Stats target | Description
---------------------+---------+-----------+---------+--------------+-------------
pd_id | integer | not null | plain | |
st_id | integer | | plain | |
status_id | integer | | plain | |
next_execution_date | bigint | | plain | |
priority | integer | | plain | |
is_active | integer | | plain | |
Indexes:
"pk_pd" PRIMARY KEY, btree (pd_id)
"idx_pd_order" btree (priority, next_execution_date) …Run Code Online (Sandbox Code Playgroud)