Inner join is the default join.
Outter join has three categories: left join, right join and full join.
starts_with()
Lateral join:
lateral
Lateral join can be (NOT must be) terribly expensive, depending on how big the perceiving table is and how expensive the subquery is. You are going to be running that subquery once per row.
Rows from:
unnest()
Filling gaps in sequences:
generate_series()
Subquery elimination:
Semi join:
Anti join:
Semi joins and anti joins are optimization for these subqueries.
Another style of subquery elimination:
Here's the fundamental defference: this 'where exists' is going to run for every row in the outer table, which can be good because the 'where exists' will short-circuit the first time it finds a true value, not continuing looking through the bookmarks table.
A use case 'where exists' is good:
Combining queries: Union, intersect, Except
'UNION ALL' doesn't remove duplicates, so it is faster than 'UNION'. If you know there's no duplicate or want to see the duplicates, prefer 'UNION ALL'.
'INTERSECT ALL' is faster than 'INTERSECT', but doesn't remove duplicates.
'EXCEPT ALL' is faster than 'EXCEPT', but doesn't remove dupplicates.
Set generating functions:
generate_series()
with ordinality
unnest()
with ordinality
json_to_recordset()
jsonb_to_recordset()
The result is the same as above.
regexp_matches()
string_to_table():
Indexing joins:
When you create a primary key, a unique constraint in a parent table, that is enforced by an index. That index is automatically created in the parent table. However, when you create a foreign key, even a foreign key constraint, the index is not automatically created in the child table.
How to improve? Create an index for the foreign key (can be a composite index, depending on the query condition often used).
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
2023-12-08 Docker - Build an application to an image and run it