Skip to content

Commit

Permalink
Для проверки ql-temp-table-index сделать параметр MAX_TOP параметризи…
Browse files Browse the repository at this point in the history
…руемым (#1312)

* #1309 Доработана проверка ql-temp-table-index

Доработана проверка ql-temp-table-index. Параметр MAX_TOP теперь
настраиваемый.
  • Loading branch information
VAGoncharov committed Apr 16, 2023
1 parent d1ce709 commit bb05425
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#### Запросы

- Доработана проверка ql-temp-table-index: параметр MAX_TOP (Макс. кол-во строк в выборке) теперь настраиваемый.

#### Права ролей

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ final class Messages
public static String TempTableHasIndex_description;
public static String TempTableHasIndex_Exclude_table_name_pattern;
public static String TempTableHasIndex_New_temporary_table_should_have_indexes;
public static String TempTableHasIndex_Parameter_max_top;
public static String TempTableHasIndex_title;
public static String UsingForUpdateCheck_description;
public static String UsingForUpdateCheck_title;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (C) 2021, 1C-Soft LLC and others.
* Copyright (C) 2023, 1C-Soft LLC and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -34,6 +34,7 @@
* This check may be enhanced in the future.
*
* @author Dmitriy Marmyshev
* @author Vadim Goncharov
*/
public class TempTableHasIndex
extends QlBasicDelegateCheck
Expand All @@ -43,7 +44,9 @@ public class TempTableHasIndex

private static final String PARAMETER_EXCLUDE_TABLE_NAME_PATTERN = "excludeObjectNamePattern"; //$NON-NLS-1$

private static final int MAX_TOP = 1000;
private static final String PARAMETER_MAX_TOP = "maxTop"; //$NON-NLS-1$

private static final int MAX_TOP_DEFAULT = 1000;

@Override
public String getCheckId()
Expand All @@ -61,16 +64,20 @@ protected void configureCheck(CheckConfigurer builder)
.issueType(IssueType.PERFORMANCE)
.extension(new StandardCheckExtension(777, getCheckId(), CorePlugin.PLUGIN_ID))
.delegate(QuerySchemaSelectQuery.class);
builder.parameter(PARAMETER_EXCLUDE_TABLE_NAME_PATTERN, String.class, StringUtils.EMPTY,
Messages.TempTableHasIndex_Exclude_table_name_pattern);
builder
.parameter(PARAMETER_EXCLUDE_TABLE_NAME_PATTERN, String.class, StringUtils.EMPTY,
Messages.TempTableHasIndex_Exclude_table_name_pattern)
.parameter(PARAMETER_MAX_TOP, Integer.class, Integer.toString(MAX_TOP_DEFAULT),
Messages.TempTableHasIndex_Parameter_max_top);
}

@Override
protected void checkQlObject(EObject object, QueryOwner owner, IQlResultAcceptor resultAceptor,
ICheckParameters parameters, IProgressMonitor monitor)
{
QuerySchemaSelectQuery selectQuery = (QuerySchemaSelectQuery)object;
if (selectQuery.getPlacementTable() == null || isTopLessThenThousand(selectQuery))
int maxTop = parameters.getInt(PARAMETER_MAX_TOP);
if (selectQuery.getPlacementTable() == null || isTopLessThenMaxTop(selectQuery, maxTop))
{
return;
}
Expand All @@ -89,15 +96,15 @@ protected void checkQlObject(EObject object, QueryOwner owner, IQlResultAcceptor
}
}

private boolean isTopLessThenThousand(QuerySchemaSelectQuery selectQuery)
private boolean isTopLessThenMaxTop(QuerySchemaSelectQuery selectQuery, int maxTop)
{
if (!selectQuery.getOperators().isEmpty() && selectQuery.getOperators().get(0).getGetRecordsCount() != null)
{
String count = selectQuery.getOperators().get(0).getGetRecordsCount();
try
{
int top = Integer.parseInt(count);
return top < MAX_TOP;
return top < maxTop;
}
catch (NumberFormatException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ TempTableHasIndex_New_temporary_table_should_have_indexes = New temporary table

TempTableHasIndex_description = Temporary table should have indexes

TempTableHasIndex_Parameter_max_top = Max rows in query

TempTableHasIndex_title = Temporary table should have indexes

UsingForUpdateCheck_description = Check if query contains "FOR UPDATE"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ TempTableHasIndex_New_temporary_table_should_have_indexes = Новая врем

TempTableHasIndex_description = Временная таблица должна содержать индексы

TempTableHasIndex_Parameter_max_top = Макс. количество строк в запросе

TempTableHasIndex_title = Временная таблица должна содержать индексы

UsingForUpdateCheck_description = Проверка наличия конструкции "ДЛЯ ИЗМЕНЕНИЯ" в запросе
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (C) 2021, 1C-Soft LLC and others.
* Copyright (C) 2023, 1C-Soft LLC and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -38,6 +38,7 @@
* Test {@link TempTableHasIndex} class that checks selection query that put to new temporary table and has indexes.
*
* @author Dmitriy Marmyshev
* @author Vadim Goncharov
*/
public class TempTableHasIndexTest
extends SingleProjectReadOnlyCheckTestBase
Expand All @@ -49,11 +50,15 @@ public class TempTableHasIndexTest

private static final String PARAMETER_EXCLUDE_TABLE_NAME_PATTERN = "excludeObjectNamePattern";

private static final String PARAMETER_MAX_TOP = "maxTop";

private static final int MAX_TOP_DEFAULT = 1000;

private TestingCheckResultAcceptor resultAcceptor;

private TestingQlResultAcceptor qlResultAcceptor;

private TestingCheckParameters emptyParameters;
private TestingCheckParameters defaultParameters;

private TempTableHasIndex check;

Expand All @@ -68,7 +73,8 @@ public void setupCheck() throws Exception
{
resultAcceptor = new TestingCheckResultAcceptor();
qlResultAcceptor = new TestingQlResultAcceptor();
emptyParameters = new TestingCheckParameters(Map.of(PARAMETER_EXCLUDE_TABLE_NAME_PATTERN, ""));
defaultParameters = new TestingCheckParameters(
Map.of(PARAMETER_EXCLUDE_TABLE_NAME_PATTERN, "", PARAMETER_MAX_TOP, MAX_TOP_DEFAULT));
QlBasicDelegateCheck.setResultAcceptor((o, f) -> qlResultAcceptor);
check = new TempTableHasIndex();
}
Expand All @@ -90,13 +96,13 @@ public void testTempTableWithoutIndex() throws Exception
EObject selectQuery = querySchema.getQueries().get(1);
assertTrue(selectQuery instanceof QuerySchemaSelectQuery);

check.check(selectQuery, resultAcceptor, emptyParameters, new NullProgressMonitor());
check.check(selectQuery, resultAcceptor, defaultParameters, new NullProgressMonitor());

assertTrue(qlResultAcceptor.getMarkers().isEmpty());

selectQuery = querySchema.getQueries().get(0);
assertTrue(selectQuery instanceof QuerySchemaSelectQuery);
check.check(selectQuery, resultAcceptor, emptyParameters, new NullProgressMonitor());
check.check(selectQuery, resultAcceptor, defaultParameters, new NullProgressMonitor());

assertFalse(qlResultAcceptor.getMarkers().isEmpty());

Expand All @@ -119,16 +125,23 @@ public void testTempTableWithoutIndexWithRecordCount() throws Exception
EObject selectQuery = querySchema.getQueries().get(1);
assertTrue(selectQuery instanceof QuerySchemaSelectQuery);

check.check(selectQuery, resultAcceptor, emptyParameters, new NullProgressMonitor());
check.check(selectQuery, resultAcceptor, defaultParameters, new NullProgressMonitor());

assertTrue(qlResultAcceptor.getMarkers().isEmpty());

selectQuery = querySchema.getQueries().get(0);
assertTrue(selectQuery instanceof QuerySchemaSelectQuery);
check.check(selectQuery, resultAcceptor, emptyParameters, new NullProgressMonitor());
check.check(selectQuery, resultAcceptor, defaultParameters, new NullProgressMonitor());

assertFalse(qlResultAcceptor.getMarkers().isEmpty());

qlResultAcceptor.getMarkers().clear();
TestingCheckParameters newParameters =
new TestingCheckParameters(Map.of(PARAMETER_EXCLUDE_TABLE_NAME_PATTERN, "", PARAMETER_MAX_TOP, 110000));
check.check(selectQuery, resultAcceptor, newParameters, new NullProgressMonitor());

assertTrue(qlResultAcceptor.getMarkers().isEmpty());

}

@Test
Expand All @@ -147,13 +160,13 @@ public void testTempTableWithIndex() throws Exception
EObject selectQuery = querySchema.getQueries().get(1);
assertTrue(selectQuery instanceof QuerySchemaSelectQuery);

check.check(selectQuery, resultAcceptor, emptyParameters, new NullProgressMonitor());
check.check(selectQuery, resultAcceptor, defaultParameters, new NullProgressMonitor());

assertTrue(qlResultAcceptor.getMarkers().isEmpty());

selectQuery = querySchema.getQueries().get(0);
assertTrue(selectQuery instanceof QuerySchemaSelectQuery);
check.check(selectQuery, resultAcceptor, emptyParameters, new NullProgressMonitor());
check.check(selectQuery, resultAcceptor, defaultParameters, new NullProgressMonitor());

assertTrue(qlResultAcceptor.getMarkers().isEmpty());
}
Expand Down

0 comments on commit bb05425

Please sign in to comment.