Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
cf902b5f
Commit
cf902b5f
authored
Mar 21, 2021
by
Adam Hegyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Try out ROW_NUMBER
Try out ROW_NUMBER
parent
d651d3d6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
4 deletions
+10
-4
lib/gitlab/object_hierarchy.rb
lib/gitlab/object_hierarchy.rb
+8
-4
spec/services/ci/register_job_service_spec.rb
spec/services/ci/register_job_service_spec.rb
+2
-0
No files found.
lib/gitlab/object_hierarchy.rb
View file @
cf902b5f
...
...
@@ -68,12 +68,14 @@ module Gitlab
expose_depth
=
hierarchy_order
.
present?
hierarchy_order
||=
:asc
recursive_query
=
base_and_ancestors_cte
(
upto
,
hierarchy_order
).
apply_to
(
model
.
all
).
distinct
# if hierarchy_order is given, the calculated `depth` should be present in SELECT
if
expose_depth
recursive_query
=
base_and_ancestors_cte
(
upto
,
hierarchy_order
).
apply_to
(
model
.
all
).
distinct
read_only
(
model
.
from
(
Arel
::
Nodes
::
As
.
new
(
recursive_query
.
arel
,
objects_table
)).
order
(
depth:
hierarchy_order
))
else
recursive_query
=
base_and_ancestors_cte
(
upto
).
apply_to
(
model
.
all
)
recursive_query
=
recursive_query
.
reselect
(
*
recursive_query
.
arel
.
projections
,
'ROW_NUMBER() OVER () as depth'
).
distinct
recursive_query
=
model
.
from
(
Arel
::
Nodes
::
As
.
new
(
recursive_query
.
arel
,
objects_table
))
read_only
(
remove_depth_and_maintain_order
(
recursive_query
,
hierarchy_order:
hierarchy_order
))
end
else
...
...
@@ -93,11 +95,13 @@ module Gitlab
def
base_and_descendants
(
with_depth:
false
)
if
use_distinct?
# Always calculate `depth`, remove it later if with_depth is false
base_cte
=
base_and_descendants_cte
(
with_depth:
true
).
apply_to
(
model
.
all
).
distinct
if
with_depth
base_cte
=
base_and_descendants_cte
(
with_depth:
true
).
apply_to
(
model
.
all
).
distinct
read_only
(
model
.
from
(
Arel
::
Nodes
::
As
.
new
(
base_cte
.
arel
,
objects_table
)).
order
(
depth: :asc
))
else
base_cte
=
base_and_descendants_cte
.
apply_to
(
model
.
all
)
base_cte
=
base_cte
.
reselect
(
*
base_cte
.
arel
.
projections
,
'ROW_NUMBER() OVER () as depth'
).
distinct
base_cte
=
model
.
from
(
Arel
::
Nodes
::
As
.
new
(
base_cte
.
arel
,
objects_table
))
read_only
(
remove_depth_and_maintain_order
(
base_cte
,
hierarchy_order: :asc
))
end
else
...
...
spec/services/ci/register_job_service_spec.rb
View file @
cf902b5f
...
...
@@ -228,6 +228,7 @@ module Ci
context
'when the use_distinct_in_register_job_object_hierarchy feature flag is enabled'
do
before
do
stub_feature_flags
(
use_distinct_in_register_job_object_hierarchy:
true
)
stub_feature_flags
(
use_distinct_for_all_object_hierarchy:
true
)
end
it
'calls DISTINCT'
do
...
...
@@ -238,6 +239,7 @@ module Ci
context
'when the use_distinct_in_register_job_object_hierarchy feature flag is disabled'
do
before
do
stub_feature_flags
(
use_distinct_in_register_job_object_hierarchy:
false
)
stub_feature_flags
(
use_distinct_for_all_object_hierarchy:
false
)
end
it
'does not call DISTINCT'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment