Skip to content
GitLab
菜单
为什么选择 GitLab
定价
联系销售
探索
为什么选择 GitLab
定价
联系销售
探索
登录
获取免费试用
主导航
搜索或转到…
项目
GitLab
管理
动态
成员
标记
计划
议题
议题看板
里程碑
迭代
需求
代码
合并请求
仓库
分支
提交
标签
仓库图
比较修订版本
代码片段
锁定的文件
构建
流水线
作业
流水线计划
测试用例
产物
部署
发布
Package registry
Container registry
模型注册表
运维
环境
Terraform 模块
监控
事件
服务台
分析
价值流分析
贡献者分析
CI/CD 分析
仓库分析
代码评审分析
议题分析
洞察
模型实验
效能分析
帮助
帮助
支持
GitLab 文档
比较 GitLab 各版本
社区论坛
为极狐GitLab 提交贡献
提交反馈
隐私声明
快捷键
?
新增功能
4
代码片段
群组
项目
显示更多面包屑
gitlab-cn
GitLab
提交
bd467c82
提交
bd467c82
编辑于
3 years ago
作者:
Dylan Griffith
浏览文件
操作
下载
补丁
差异文件
Minor docs improvements for multiple_databass.md
Suggestions from tech writer.
上级
a0a39f65
No related branches found
分支 包含提交
No related tags found
标签 包含提交
无相关合并请求
变更
1
隐藏空白变更内容
行内
左右并排
显示
1 个更改的文件
doc/development/database/multiple_databases.md
+13
-14
13 个添加, 14 个删除
doc/development/database/multiple_databases.md
有
13 个添加
和
14 个删除
doc/development/database/multiple_databases.md
+
13
−
14
浏览文件 @
bd467c82
...
@@ -113,7 +113,7 @@ patterns may apply to future cases.
...
@@ -113,7 +113,7 @@ patterns may apply to future cases.
The simplest solution we've seen several times now has been an existing scope
The simplest solution we've seen several times now has been an existing scope
that is unused. This is the easiest example to fix. So the first step is to
that is unused. This is the easiest example to fix. So the first step is to
investigate if the code is unused and then
simply
remove it. These are some
investigate if the code is unused and then remove it. These are some
real examples:
real examples:
-
<https://gitlab.com/gitlab-org/gitlab/-/merge_requests/67162>
-
<https://gitlab.com/gitlab-org/gitlab/-/merge_requests/67162>
...
@@ -135,12 +135,12 @@ find that nobody is using these metrics, so we can remove them.
...
@@ -135,12 +135,12 @@ find that nobody is using these metrics, so we can remove them.
The
`includes`
and
`preload`
methods in Rails are both ways to avoid an N+1
The
`includes`
and
`preload`
methods in Rails are both ways to avoid an N+1
query. The
`includes`
method in Rails uses a heuristic approach to determine
query. The
`includes`
method in Rails uses a heuristic approach to determine
whether or not
it needs to
actually
join to the table or
whether
it can load
if
it needs to join to the table
,
or
if
it can load
all of the
all the
records in a separate query.
It
assumes it needs to join if it thinks
records in a separate query.
This method
assumes it needs to join if it thinks
you need to query the columns from the other table
in some way
, but sometimes
you need to query the columns from the other table, but sometimes
this method gets it wrong and
it
executes a join even when
it isn'
t needed. In
this method gets it wrong and executes a join even when
no
t needed. In
this case using
`preload`
to explicitly load the data in a separate query
will
this case using
`preload`
to explicitly load the data in a separate query
allow you to avoid the join while still avoiding the N+1 query.
allow
s
you to avoid the join
,
while still avoiding the N+1 query.
You can see a real example of this solution being used in
You can see a real example of this solution being used in
<https://gitlab.com/gitlab-org/gitlab/-/merge_requests/67655>
.
<https://gitlab.com/gitlab-org/gitlab/-/merge_requests/67655>
.
...
@@ -260,13 +260,12 @@ A quick checklist for fixing a specific join query would be:
...
@@ -260,13 +260,12 @@ A quick checklist for fixing a specific join query would be:
#### How to validate you have correctly removed a cross-join
#### How to validate you have correctly removed a cross-join
We have introduced a method you can use in RSpec tests to validate all SQL
Using RSpec tests, you can validate all SQL queries within a code block to
queries within a code block to ensure that none of them are joining across the
ensure that none of them are joining across the two databases. This is a useful
2 databases. This is a useful tool to confirm you have correctly fixed an
tool to confirm you have correctly fixed an existing cross-join.
existing cross-join.
At some point in the future we will have fixed all cross-joins and this tool
At some point in the future we will have fixed all cross-joins and this tool
will run by default in all tests
but for now it
needs to be explicitly enabled
will run by default in all tests
. For now, the tool
needs to be explicitly enabled
for your test.
for your test.
You can use this method like so:
You can use this method like so:
...
@@ -279,8 +278,8 @@ it 'does not join across databases' do
...
@@ -279,8 +278,8 @@ it 'does not join across databases' do
end
end
```
```
This will raise an exception if the query joins across the
2
databases. The
This will raise an exception if the query joins across the
two
databases. The
above
example is fixed by removing the join like so:
previous
example is fixed by removing the join
,
like so:
```
ruby
```
ruby
it
'does not join across databases'
do
it
'does not join across databases'
do
...
...
此差异已折叠。
点击以展开。
预览
0%
加载中
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
保存评论
取消
想要评论请
注册
或
登录