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
39f1a95d
Commit
39f1a95d
authored
Jul 02, 2021
by
Jonston Chan
Committed by
Marcia Ramos
Jul 02, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Docs: Put code in sql.md in code blocks
parent
e8f349c5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
6 deletions
+6
-6
doc/development/sql.md
doc/development/sql.md
+6
-6
No files found.
doc/development/sql.md
View file @
39f1a95d
...
@@ -70,7 +70,7 @@ WHERE title ILIKE '%Draft:%';
...
@@ -70,7 +70,7 @@ WHERE title ILIKE '%Draft:%';
Because the value for
`ILIKE`
starts with a wildcard the database is not able to
Because the value for
`ILIKE`
starts with a wildcard the database is not able to
use an index as it doesn't know where to start scanning the indexes.
use an index as it doesn't know where to start scanning the indexes.
Luckily, PostgreSQL _does_ provide a solution: trigram G
IN
indexes. These
Luckily, PostgreSQL _does_ provide a solution: trigram G
eneralized Inverted Index (GIN)
indexes. These
indexes can be created as follows:
indexes can be created as follows:
```
sql
```
sql
...
@@ -261,9 +261,9 @@ from `ActiveRecord::Base`.
...
@@ -261,9 +261,9 @@ from `ActiveRecord::Base`.
## Use UNIONs
## Use UNIONs
UNION
s aren't very commonly used in most Rails applications but they're very
`UNION`
s aren't very commonly used in most Rails applications but they're very
powerful and useful.
In most applications queries tend to use a lot of JOIN
s to
powerful and useful.
Queries tend to use a lot of
`JOIN`
s to
get related data or data based on certain criteria, but
JOIN
performance can
get related data or data based on certain criteria, but
`JOIN`
performance can
quickly deteriorate as the data involved grows.
quickly deteriorate as the data involved grows.
For example, if you want to get a list of projects where the name contains a
For example, if you want to get a list of projects where the name contains a
...
@@ -279,7 +279,7 @@ OR namespaces.name ILIKE '%gitlab%';
...
@@ -279,7 +279,7 @@ OR namespaces.name ILIKE '%gitlab%';
```
```
Using a large database this query can easily take around 800 milliseconds to
Using a large database this query can easily take around 800 milliseconds to
run. Using a
UNION
we'd write the following instead:
run. Using a
`UNION`
we'd write the following instead:
```
sql
```
sql
SELECT
projects
.
*
SELECT
projects
.
*
...
@@ -301,7 +301,7 @@ This doesn't mean you should start using UNIONs everywhere, but it's something
...
@@ -301,7 +301,7 @@ This doesn't mean you should start using UNIONs everywhere, but it's something
to keep in mind when using lots of JOINs in a query and filtering out records
to keep in mind when using lots of JOINs in a query and filtering out records
based on the joined data.
based on the joined data.
GitLab comes with a
`Gitlab::SQL::Union`
class that can be used to build a
UNION
GitLab comes with a
`Gitlab::SQL::Union`
class that can be used to build a
`UNION`
of multiple
`ActiveRecord::Relation`
objects. You can use this class as
of multiple
`ActiveRecord::Relation`
objects. You can use this class as
follows:
follows:
...
...
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