Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1138,8 +1138,8 @@ private Optional<RexLiteral> extractAliasLiteral(RexNode node) {
public RelNode visitJoin(Join node, CalcitePlanContext context) {
List<UnresolvedPlan> children = node.getChildren();
children.forEach(c -> analyze(c, context));
// add join.subsearch_maxout limit to subsearch side
if (context.sysLimit.joinSubsearchLimit() >= 0) {
// add join.subsearch_maxout limit to subsearch side, 0 and negative means unlimited.
if (context.sysLimit.joinSubsearchLimit() > 0) {
PlanUtils.replaceTop(
context.relBuilder,
LogicalSystemLimit.create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,8 @@ private RelNode resolveSubqueryPlan(
context.setResolvingJoinCondition(false);
}
subquery.accept(planVisitor, context);

// add subsearch.maxout limit to exists-in subsearch, 0 and negative means unlimited
if (context.sysLimit.subsearchLimit() > 0 && !(subqueryExpression instanceof ScalarSubquery)) {
// Add subsearch.maxout limit to exists-in subsearch:
// Cannot add system limit to the top of subquery simply.
// Instead, add system limit under the correlated conditions.
SubsearchUtils.SystemLimitInsertionShuttle shuttle =
Expand All @@ -536,10 +535,6 @@ private RelNode resolveSubqueryPlan(
}
// pop the inner plan
RelNode subqueryRel = context.relBuilder.build();
// if maxout = 0, return empty results
if (context.sysLimit.subsearchLimit() == 0) {
subqueryRel = context.relBuilder.values(subqueryRel.getRowType()).build();
}
// clear the exists subquery resolving state
// restore to the previous state
if (isResolvingJoinConditionOuter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static SysLimit fromSettings(Settings settings) {
}

/** No limitation on subsearch */
public static SysLimit UNLIMITED_SUBSEARCH = new SysLimit(10000, -1, -1);
public static SysLimit UNLIMITED_SUBSEARCH = new SysLimit(10000, 0, 0);

/** For testing only */
public static SysLimit DEFAULT = new SysLimit(10000, 10000, 50000);
Expand Down
8 changes: 4 additions & 4 deletions docs/user/ppl/admin/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ plugins.ppl.subsearch.maxout
Description
-----------

The size configures the maximum of rows to return from subsearch. The default value is: ``10000``. A value of ``-1`` indicates that the restriction is unlimited.
The size configures the maximum of rows to return from subsearch. The default value is: ``10000``. A value of ``0`` indicates that the restriction is unlimited.

Version
-------
Expand All @@ -303,14 +303,14 @@ Change the subsearch.maxout to unlimited::

sh$ curl -sS -H 'Content-Type: application/json' \
... -X PUT localhost:9200/_plugins/_query/settings \
... -d '{"persistent" : {"plugins.ppl.subsearch.maxout" : "-1"}}'
... -d '{"persistent" : {"plugins.ppl.subsearch.maxout" : "0"}}'
{
"acknowledged": true,
"persistent": {
"plugins": {
"ppl": {
"subsearch": {
"maxout": "-1"
"maxout": "0"
}
}
}
Expand All @@ -324,7 +324,7 @@ plugins.ppl.join.subsearch_maxout
Description
-----------

The size configures the maximum of rows from subsearch to join against. This configuration impacts ``join`` command. The default value is: ``50000``. A value of ``-1`` indicates that the restriction is unlimited.
The size configures the maximum of rows from subsearch to join against. This configuration impacts ``join`` command. The default value is: ``50000``. A value of ``0`` indicates that the restriction is unlimited.

Version
-------
Expand Down
2 changes: 1 addition & 1 deletion docs/user/ppl/cmd/join.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Result set::
plugins.ppl.join.subsearch_maxout
---------------------------------

The size configures the maximum of rows from subsearch to join against. The default value is: ``50000``. A value of ``-1`` indicates that the restriction is unlimited.
The size configures the maximum of rows from subsearch to join against. The default value is: ``50000``. A value of ``0`` indicates that the restriction is unlimited.

Change the join.subsearch_maxout to 5000::

Expand Down
4 changes: 2 additions & 2 deletions docs/user/ppl/cmd/subquery.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ Result set::
plugins.ppl.subsearch.maxout
----------------------------

The size configures the maximum of rows to return from subsearch. The default value is: ``10000``. A value of ``-1`` indicates that the restriction is unlimited.
The size configures the maximum of rows to return from subsearch. The default value is: ``10000``. A value of ``0`` indicates that the restriction is unlimited.

Change the subsearch.maxout to unlimited::

sh$ curl -sS -H 'Content-Type: application/json' \
... -X PUT localhost:9200/_plugins/_query/settings \
... -d '{"persistent" : {"plugins.ppl.subsearch.maxout" : "-1"}}'
... -d '{"persistent" : {"plugins.ppl.subsearch.maxout" : "0"}}'
{
"acknowledged": true,
"persistent": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ public void testSubsearchMaxOutUncorrelated() throws IOException {
}

@Test
public void testSubsearchMaxOutZero1() throws IOException {
public void testUncorrelatedSubsearchMaxOutZeroMeansUnlimited() throws IOException {
setSubsearchMaxOut(0);
JSONObject result =
executeQuery(
Expand All @@ -390,24 +390,12 @@ public void testSubsearchMaxOutZero1() throws IOException {
+ "| sort - salary"
+ "| fields id, name, salary",
TEST_INDEX_WORKER, TEST_INDEX_WORK_INFORMATION));
verifyNumOfRows(result, 0);

result =
executeQuery(
String.format(
"source = %s"
+ "| where not exists ["
+ " source = %s | where name = 'Tom'"
+ " ]"
+ "| sort - salary"
+ "| fields id, name, salary",
TEST_INDEX_WORKER, TEST_INDEX_WORK_INFORMATION));
verifyNumOfRows(result, 7);
resetSubsearchMaxOut();
}

@Test
public void testSubsearchMaxOutZero2() throws IOException {
public void testCorrelatedSubsearchMaxOutZeroMeansUnlimited() throws IOException {
setSubsearchMaxOut(0);
JSONObject result =
executeQuery(
Expand All @@ -419,7 +407,7 @@ public void testSubsearchMaxOutZero2() throws IOException {
+ "| sort - salary"
+ "| fields id, name, salary",
TEST_INDEX_WORKER, TEST_INDEX_WORK_INFORMATION));
verifyNumOfRows(result, 0);
verifyNumOfRows(result, 5);
result =
executeQuery(
String.format(
Expand All @@ -430,12 +418,12 @@ public void testSubsearchMaxOutZero2() throws IOException {
+ "| sort - salary"
+ "| fields id, name, salary",
TEST_INDEX_WORKER, TEST_INDEX_WORK_INFORMATION));
verifyNumOfRows(result, 7);
verifyNumOfRows(result, 2);
resetSubsearchMaxOut();
}

@Test
public void testSubsearchMaxOutUnlimited() throws IOException {
public void testSubsearchMaxOutNegativeMeansUnlimited() throws IOException {
setSubsearchMaxOut(-1);
JSONObject result =
executeQuery(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ public void testInCorrelatedSubqueryMaxOut() throws IOException {
}

@Test
public void testSubsearchMaxOutZero() throws IOException {
public void testSubsearchMaxOutZeroMeansUnlimited() throws IOException {
setSubsearchMaxOut(0);
JSONObject result =
executeQuery(
Expand All @@ -416,7 +416,7 @@ public void testSubsearchMaxOutZero() throws IOException {
+ "| fields id, name, salary",
TEST_INDEX_WORKER, TEST_INDEX_WORK_INFORMATION));
verifySchema(result, schema("id", "int"), schema("name", "string"), schema("salary", "int"));
verifyNumOfRows(result, 0);
verifyNumOfRows(result, 5);
resetSubsearchMaxOut();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public void testNestedScalarSubqueryWithTableAlias() throws IOException {
}

@Test
public void testSubsearchMaxOutZero() throws IOException {
public void testSubsearchMaxOutZeroMeansUnlimited() throws IOException {
setSubsearchMaxOut(0);
JSONObject result =
executeQuery(
Expand All @@ -322,7 +322,7 @@ public void testSubsearchMaxOutZero() throws IOException {
+ " ]"
+ "| fields id, name",
TEST_INDEX_WORKER, TEST_INDEX_WORK_INFORMATION));
verifyNumOfRows(result, 0);
verifyNumOfRows(result, 5);
resetSubsearchMaxOut();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.calcite.tools.RelBuilder;
import org.junit.jupiter.api.Test;
import org.opensearch.sql.calcite.CalcitePlanContext;
import org.opensearch.sql.calcite.SysLimit;
import org.opensearch.sql.calcite.utils.CalciteToolsHelper.OpenSearchRelRunners;
import org.opensearch.sql.common.setting.Settings;
import org.opensearch.sql.executor.QueryType;
Expand Down Expand Up @@ -175,6 +176,6 @@ private CalcitePlanContext createCalcitePlanContext() {

Settings settings = getSettings();
return CalcitePlanContext.create(
config.build(), settings.getSettingValue(Settings.Key.QUERY_SIZE_LIMIT), QueryType.PPL);
config.build(), SysLimit.fromSettings(settings), QueryType.PPL);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,13 @@ public class OpenSearchSettings extends Settings {
Setting.intSetting(
Key.PPL_SUBSEARCH_MAXOUT.getKeyValue(),
10000,
-1,
Setting.Property.NodeScope,
Setting.Property.Dynamic);

public static final Setting<?> PPL_JOIN_SUBSEARCH_MAXOUT_SETTING =
Setting.intSetting(
Key.PPL_JOIN_SUBSEARCH_MAXOUT.getKeyValue(),
50000,
-1,
Setting.Property.NodeScope,
Setting.Property.Dynamic);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ public void testSubsearchMaxOutUncorrelated2() {
}

@Test
public void testSubsearchMaxOutZero() {
public void testSubsearchMaxOutZeroMeansUnlimited() {
doReturn(0).when(settings).getSettingValue(Settings.Key.PPL_SUBSEARCH_MAXOUT);
String ppl =
"""
Expand All @@ -742,7 +742,8 @@ public void testSubsearchMaxOutZero() {
+ "LogicalProject(EMPNO=[$0], ENAME=[$1])\n"
+ " LogicalSort(sort0=[$0], dir0=[DESC-nulls-last])\n"
+ " LogicalFilter(condition=[EXISTS({\n"
+ "LogicalValues(tuples=[[]])\n"
+ "LogicalFilter(condition=[AND(=($cor0.SAL, $2), >($1, 1000.0:DECIMAL(5, 1)))])\n"
+ " LogicalTableScan(table=[[scott, SALGRADE]])\n"
+ "})], variablesSet=[[$cor0]])\n"
+ " LogicalTableScan(table=[[scott, EMP]])\n";
verifyLogical(root, expectedLogical);
Expand All @@ -751,14 +752,14 @@ public void testSubsearchMaxOutZero() {
"SELECT `EMPNO`, `ENAME`\n"
+ "FROM `scott`.`EMP`\n"
+ "WHERE EXISTS (SELECT *\n"
+ "FROM (VALUES (NULL, NULL, NULL)) `t` (`GRADE`, `LOSAL`, `HISAL`)\n"
+ "WHERE 1 = 0)\n"
+ "FROM `scott`.`SALGRADE`\n"
+ "WHERE `EMP`.`SAL` = `HISAL` AND `LOSAL` > 1000.0)\n"
+ "ORDER BY `EMPNO` DESC";
verifyPPLToSparkSQL(root, expectedSparkSql);
}

@Test
public void testSubsearchMaxOutUnlimited() {
public void testSubsearchMaxOutNegativeMeansUnlimited() {
doReturn(-1).when(settings).getSettingValue(Settings.Key.PPL_SUBSEARCH_MAXOUT);
String ppl =
"""
Expand All @@ -780,14 +781,5 @@ public void testSubsearchMaxOutUnlimited() {
+ "})], variablesSet=[[$cor0]])\n"
+ " LogicalTableScan(table=[[scott, EMP]])\n";
verifyLogical(root, expectedLogical);

String expectedSparkSql =
"SELECT `EMPNO`, `ENAME`\n"
+ "FROM `scott`.`EMP`\n"
+ "WHERE EXISTS (SELECT *\n"
+ "FROM `scott`.`SALGRADE`\n"
+ "WHERE `EMP`.`SAL` = `HISAL` AND `LOSAL` > 1000.0)\n"
+ "ORDER BY `EMPNO` DESC";
verifyPPLToSparkSQL(root, expectedSparkSql);
}
}
Loading