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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
259493bb
Commit
259493bb
authored
Jul 24, 2019
by
Andreas Brandl
Committed by
Nick Thomas
Jul 24, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable tablesample count strategy by default
https://gitlab.com/gitlab-org/gitlab-ce/issues/58792
parent
25698fda
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
12 additions
and
78 deletions
+12
-78
changelogs/unreleased/ab-count-strategies.yml
changelogs/unreleased/ab-count-strategies.yml
+5
-0
lib/gitlab/database/count.rb
lib/gitlab/database/count.rb
+5
-7
lib/gitlab/database/count/exact_count_strategy.rb
lib/gitlab/database/count/exact_count_strategy.rb
+0
-4
lib/gitlab/database/count/reltuples_count_strategy.rb
lib/gitlab/database/count/reltuples_count_strategy.rb
+0
-4
lib/gitlab/database/count/tablesample_count_strategy.rb
lib/gitlab/database/count/tablesample_count_strategy.rb
+0
-4
spec/lib/gitlab/database/count/exact_count_strategy_spec.rb
spec/lib/gitlab/database/count/exact_count_strategy_spec.rb
+0
-14
spec/lib/gitlab/database/count/reltuples_count_strategy_spec.rb
...ib/gitlab/database/count/reltuples_count_strategy_spec.rb
+0
-14
spec/lib/gitlab/database/count/tablesample_count_strategy_spec.rb
.../gitlab/database/count/tablesample_count_strategy_spec.rb
+0
-18
spec/lib/gitlab/database/count_spec.rb
spec/lib/gitlab/database/count_spec.rb
+2
-13
No files found.
changelogs/unreleased/ab-count-strategies.yml
0 → 100644
View file @
259493bb
---
title
:
Use tablesample approximate counting by default.
merge_request
:
31048
author
:
type
:
performance
lib/gitlab/database/count.rb
View file @
259493bb
...
@@ -37,16 +37,14 @@ module Gitlab
...
@@ -37,16 +37,14 @@ module Gitlab
# @return [Hash] of Model -> count mapping
# @return [Hash] of Model -> count mapping
def
self
.
approximate_counts
(
models
,
strategies:
[
TablesampleCountStrategy
,
ReltuplesCountStrategy
,
ExactCountStrategy
])
def
self
.
approximate_counts
(
models
,
strategies:
[
TablesampleCountStrategy
,
ReltuplesCountStrategy
,
ExactCountStrategy
])
strategies
.
each_with_object
({})
do
|
strategy
,
counts_by_model
|
strategies
.
each_with_object
({})
do
|
strategy
,
counts_by_model
|
if
strategy
.
enabled?
models_with_missing_counts
=
models
-
counts_by_model
.
keys
models_with_missing_counts
=
models
-
counts_by_model
.
keys
break
counts_by_model
if
models_with_missing_counts
.
empty?
break
counts_by_model
if
models_with_missing_counts
.
empty?
counts
=
strategy
.
new
(
models_with_missing_counts
).
count
counts
=
strategy
.
new
(
models_with_missing_counts
).
count
counts
.
each
do
|
model
,
count
|
counts
.
each
do
|
model
,
count
|
counts_by_model
[
model
]
=
count
counts_by_model
[
model
]
=
count
end
end
end
end
end
end
end
...
...
lib/gitlab/database/count/exact_count_strategy.rb
View file @
259493bb
...
@@ -23,10 +23,6 @@ module Gitlab
...
@@ -23,10 +23,6 @@ module Gitlab
rescue
*
CONNECTION_ERRORS
rescue
*
CONNECTION_ERRORS
{}
{}
end
end
def
self
.
enabled?
true
end
end
end
end
end
end
end
...
...
lib/gitlab/database/count/reltuples_count_strategy.rb
View file @
259493bb
...
@@ -31,10 +31,6 @@ module Gitlab
...
@@ -31,10 +31,6 @@ module Gitlab
{}
{}
end
end
def
self
.
enabled?
Gitlab
::
Database
.
postgresql?
end
private
private
# Models using single-type inheritance (STI) don't work with
# Models using single-type inheritance (STI) don't work with
...
...
lib/gitlab/database/count/tablesample_count_strategy.rb
View file @
259493bb
...
@@ -28,10 +28,6 @@ module Gitlab
...
@@ -28,10 +28,6 @@ module Gitlab
{}
{}
end
end
def
self
.
enabled?
Gitlab
::
Database
.
postgresql?
&&
Feature
.
enabled?
(
:tablesample_counts
)
end
private
private
def
perform_count
(
model
,
estimate
)
def
perform_count
(
model
,
estimate
)
...
...
spec/lib/gitlab/database/count/exact_count_strategy_spec.rb
View file @
259493bb
...
@@ -23,18 +23,4 @@ describe Gitlab::Database::Count::ExactCountStrategy do
...
@@ -23,18 +23,4 @@ describe Gitlab::Database::Count::ExactCountStrategy do
expect
(
subject
).
to
eq
({})
expect
(
subject
).
to
eq
({})
end
end
end
end
describe
'.enabled?'
do
it
'is enabled for PostgreSQL'
do
allow
(
Gitlab
::
Database
).
to
receive
(
:postgresql?
).
and_return
(
true
)
expect
(
described_class
.
enabled?
).
to
be_truthy
end
it
'is enabled for MySQL'
do
allow
(
Gitlab
::
Database
).
to
receive
(
:postgresql?
).
and_return
(
false
)
expect
(
described_class
.
enabled?
).
to
be_truthy
end
end
end
end
spec/lib/gitlab/database/count/reltuples_count_strategy_spec.rb
View file @
259493bb
...
@@ -48,18 +48,4 @@ describe Gitlab::Database::Count::ReltuplesCountStrategy do
...
@@ -48,18 +48,4 @@ describe Gitlab::Database::Count::ReltuplesCountStrategy do
end
end
end
end
end
end
describe
'.enabled?'
do
it
'is enabled for PostgreSQL'
do
allow
(
Gitlab
::
Database
).
to
receive
(
:postgresql?
).
and_return
(
true
)
expect
(
described_class
.
enabled?
).
to
be_truthy
end
it
'is disabled for MySQL'
do
allow
(
Gitlab
::
Database
).
to
receive
(
:postgresql?
).
and_return
(
false
)
expect
(
described_class
.
enabled?
).
to
be_falsey
end
end
end
end
spec/lib/gitlab/database/count/tablesample_count_strategy_spec.rb
View file @
259493bb
...
@@ -56,22 +56,4 @@ describe Gitlab::Database::Count::TablesampleCountStrategy do
...
@@ -56,22 +56,4 @@ describe Gitlab::Database::Count::TablesampleCountStrategy do
end
end
end
end
end
end
describe
'.enabled?'
do
before
do
stub_feature_flags
(
tablesample_counts:
true
)
end
it
'is enabled for PostgreSQL'
do
allow
(
Gitlab
::
Database
).
to
receive
(
:postgresql?
).
and_return
(
true
)
expect
(
described_class
.
enabled?
).
to
be_truthy
end
it
'is disabled for MySQL'
do
allow
(
Gitlab
::
Database
).
to
receive
(
:postgresql?
).
and_return
(
false
)
expect
(
described_class
.
enabled?
).
to
be_falsey
end
end
end
end
spec/lib/gitlab/database/count_spec.rb
View file @
259493bb
...
@@ -9,24 +9,13 @@ describe Gitlab::Database::Count do
...
@@ -9,24 +9,13 @@ describe Gitlab::Database::Count do
let
(
:models
)
{
[
Project
,
Identity
]
}
let
(
:models
)
{
[
Project
,
Identity
]
}
context
'.approximate_counts'
do
context
'.approximate_counts'
do
context
'selecting strategies'
do
let
(
:strategies
)
{
[
double
(
's1'
,
enabled?:
true
),
double
(
's2'
,
enabled?:
false
)]
}
it
'uses only enabled strategies'
do
expect
(
strategies
[
0
]).
to
receive
(
:new
).
and_return
(
double
(
'strategy1'
,
count:
{}))
expect
(
strategies
[
1
]).
not_to
receive
(
:new
)
described_class
.
approximate_counts
(
models
,
strategies:
strategies
)
end
end
context
'fallbacks'
do
context
'fallbacks'
do
subject
{
described_class
.
approximate_counts
(
models
,
strategies:
strategies
)
}
subject
{
described_class
.
approximate_counts
(
models
,
strategies:
strategies
)
}
let
(
:strategies
)
do
let
(
:strategies
)
do
[
[
double
(
's1'
,
enabled?:
true
,
new:
first_strategy
),
double
(
's1'
,
new:
first_strategy
),
double
(
's2'
,
enabled?:
true
,
new:
second_strategy
)
double
(
's2'
,
new:
second_strategy
)
]
]
end
end
...
...
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