Skip to content

Commit abd71df

Browse files
Apply translations in en
translation completed for the source file '/docs/diagnostics/LogicalOrInTheWhereSectionOfQuery.md' on the 'en' language.
1 parent 92ec8dd commit abd71df

File tree

1 file changed

+47
-37
lines changed

1 file changed

+47
-37
lines changed

docs/en/diagnostics/LogicalOrInTheWhereSectionOfQuery.md

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,104 @@
11
# Using a logical "OR" in the "WHERE" section of a query (LogicalOrInTheWhereSectionOfQuery)
22

33
<!-- Блоки выше заполняются автоматически, не трогать -->
4-
## Description
4+
## Описание диагностики
55
<!-- Описание диагностики заполняется вручную. Необходимо понятным языком описать смысл и схему работу -->
6-
Do not use `OR` in the `WHERE` section of the query. This can lead to the DBMS being unable to use the indexes of the tables and will perform scans, which will increase the query time and the likelihood of locks occurring. Instead, you should split one query into several and combine the results.
6+
Не следует использовать `ИЛИ` в секции `ГДЕ` запроса. Это может привести к тому, что СУБД не сможет использовать
7+
индексы таблиц и будет выполнять сканирование, что увеличит время работы запроса и вероятность возникновения блокировок.
8+
Вместо этого следует разбить один запрос на несколько и объединить результаты.
9+
10+
## Примеры
11+
<!-- В данном разделе приводятся примеры, на которые диагностика срабатывает, а также можно привести пример, как можно исправить ситуацию -->
12+
13+
For example, query:
714

8-
For example, the query
915
```bsl
10-
SELECT Item.Name FROM Directory.Products AS Item
11-
WHERE Article = "001" OR Price = 10
16+
SELECT Goods.Description FROM Catalog.Goods AS Goods
17+
WHERE Code = "001" OR Cost = 10
1218
```
1319

14-
should be replaced with a query
20+
should instead of a query:
1521

1622
```bsl
17-
SELECT Product.Name FROM Directory.Products AS Product WHERE Article = "001"
23+
SELECT Goods.Description FROM Catalog.Goods AS Goods
24+
WHERE Code = "001"
25+
1826
UNION ALL
19-
SELECT Product.Name FROM Directory.Products AS Product WHERE Price = 10
27+
28+
SELECT Goods.Description FROM Catalog.Goods AS Goods
29+
WHERE Cost = 10
30+
2031
```
21-
> **Important** - the current diagnostic implementation triggers any `OR` in the `WHERE` section and may give false positives for some conditions.
2232

23-
1) In the main condition, the `OR` operator can be used only for the last used or the only index field, when the `OR` operator can be replaced with the `IN` operator.
33+
>**Important** - the current implementation of the diagnostic triggers on any `OR` in the `WHERE` section and may issue false positives for some conditions.
2434
25-
CORRECT:
35+
1) In the main condition, the `OR` operator can only be used for the last used or the only index field, when the `OR` operator can be replaced by the `IN` operator.
36+
37+
Correct:
2638

2739
```bsl
2840
WHERE
29-
Table.Field = &Value1
30-
OR Table.Field = &Value2
41+
Table.Filed = &Value1
42+
OR Table.Filed = &Value2
3143
```
3244

33-
since can be rewritten using the `IN` operator (you don't need to rewrite it specifically, you can leave it as it is):
45+
because can be rewritten using the `IN` operator (you dont need to specifically rewrite it, you can leave it as it is):
3446

3547
```bsl
3648
WHERE
3749
Table.Field IN (&Value)
3850
```
3951

40-
WRONG:
52+
Incorrect:
4153

4254
```bsl
4355
WHERE
44-
Table.Field1 = &Value1
45-
OR Table.Field2 = &Value2
56+
Table.Field1 = &Value1
57+
OR Table.Field2 = &Value2
4658
```
4759

48-
cannot be overwritten with `IN`, but can be overwritten with `UNION ALL` (each field Field1 and Field2 must be indexed):
60+
cannot be rewritten with `IN`, but can be rewritten with `UNION ALL` (each Field1 and Field2 must be indexed):
4961

5062
```bsl
5163
WHERE
52-
Table.Field1 = &Value1
64+
Table.Field1 = &Value1
5365
54-
ОБЪЕДИНИТЬ ВСЕ
66+
UNION ALL
5567
5668
WHERE
57-
Table.Field2 = &Value1
69+
Table.Field2 = &Value1
5870
```
59-
> Note: replacing `OR` with `UNION ALL` is not always possible, make sure the result is indeed the same as `OR` before use.
6071

61-
2) In an additional condition, the OR operator can be used without restrictions.
72+
>Note: it is not always possible to replace `OR` with `UNION ALL`, make sure the result is really the same as with `OR` before applying.
6273
63-
CORRECT 1:
74+
2) Additionally, the 'OR' operator can be used without restriction.
75+
76+
Correct:
6477

6578
```bsl
6679
WHERE
67-
Table.Field1 = &Value1 // Main condition (uses index)
68-
AND // Additional condition (you can use OR)
69-
(Table.Field2 = &Value2 OR Table.Field3 = &Value3)
80+
Table.Filed1 = &Value1 // Main condition (use index)
81+
AND // Addition condition (can use OR)
82+
(Table.Filed2 = &Value2 OR Table.Filed3 = &Value3)
7083
```
7184

72-
CORRECT 2:
85+
Correct:
7386

7487
```bsl
7588
WHERE
76-
(Table.Field1 = &Value1 OR Table.Field1 = &Value2)
77-
AND
78-
(Table.Field2 = &Value3 OR Table.Field2 = &Value4)
89+
(Table.Filed1 = &Value1 OR Table.Filed1 = &Value2)
90+
AND
91+
(Table.Filed2 = &Value3 OR Table.Filed2 = &Value4)
7992
```
8093

81-
since can be rewritten using the IN operator (you don't need to rewrite it specifically, you can leave it as it is):
94+
because can be rewritten using 'IN' (no special rewriting needed, can be left as is):
8295

8396
```bsl
8497
WHERE
85-
Table.Field1 B (&Values1) // Main condition
86-
AND Table.Field2 B (&Values2) // Additional condition (or vice versa)
98+
Table.Field1 IN (&Value1) // Main condition
99+
AND Table.Field2 IN (&Value2) // Additional condition (or vice versa)
87100
```
88101

89-
## Examples
90-
<!-- В данном разделе приводятся примеры, на которые диагностика срабатывает, а также можно привести пример, как можно исправить ситуацию -->
91-
92102
## Sources
93103
<!-- Необходимо указывать ссылки на все источники, из которых почерпнута информация для создания диагностики -->
94104

0 commit comments

Comments
 (0)