Skip to content
Closed
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 @@ -183,7 +183,7 @@ public Optional<LimitApplicationResult<ConnectorTableHandle>> applyLimit(Connect
InformationSchemaTableHandle table = (InformationSchemaTableHandle) handle;

if (table.getLimit().isPresent() && table.getLimit().getAsLong() <= limit) {
return Optional.empty();
return Optional.of(new LimitApplicationResult<>(table, true, false));
}

return Optional.of(new LimitApplicationResult<>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,13 @@ public Optional<LimitApplicationResult<ConnectorTableHandle>> applyLimit(Connect
return Optional.empty();
}

boolean limitGuaranteed = jdbcClient.isLimitGuaranteed(session);

if (handle.getLimit().isPresent() && handle.getLimit().getAsLong() <= limit) {
return Optional.empty();
if (!limitGuaranteed) {
return Optional.empty();
}
return Optional.of(new LimitApplicationResult<>(handle, limitGuaranteed, false));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

connector should return non-empty only when plan changes.
per io.trino.spi.connector.ConnectorMetadata#applyLimit doc:

     * Connectors can indicate whether they don't support limit pushdown or that the action had no effect
     * by returning {@link Optional#empty()}. 

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think instead, we would need "redundant limit pruning rule"
i.e. a connector needs to be able to tell the engine what's the max cardinality to be returned
(just like it can return enforced predicates)

}

handle = new JdbcTableHandle(
Expand All @@ -452,7 +457,7 @@ public Optional<LimitApplicationResult<ConnectorTableHandle>> applyLimit(Connect
handle.getOtherReferencedTables(),
handle.getNextSyntheticColumnId());

return Optional.of(new LimitApplicationResult<>(handle, jdbcClient.isLimitGuaranteed(session), false));
return Optional.of(new LimitApplicationResult<>(handle, limitGuaranteed, false));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ public Optional<LimitApplicationResult<ConnectorTableHandle>> applyLimit(Connect
MemoryTableHandle table = (MemoryTableHandle) handle;

if (table.getLimit().isPresent() && table.getLimit().getAsLong() <= limit) {
return Optional.empty();
return Optional.of(new LimitApplicationResult<>(table, true, true));
}

return Optional.of(new LimitApplicationResult<>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,12 @@ public Optional<LimitApplicationResult<ConnectorTableHandle>> applyLimit(Connect
return Optional.empty();
}

// MongoDB doesn't support limit number greater than integer max
if (limit > Integer.MAX_VALUE) {
return Optional.empty();
if (handle.getLimit().isPresent() && handle.getLimit().getAsInt() <= limit) {
return Optional.of(new LimitApplicationResult<>(handle, true, false));
}

if (handle.getLimit().isPresent() && handle.getLimit().getAsInt() <= limit) {
// MongoDB doesn't support limit number greater than integer max
if (limit > Integer.MAX_VALUE) {
return Optional.empty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,14 @@ public ConnectorTableProperties getTableProperties(ConnectorSession session, Con
public Optional<LimitApplicationResult<ConnectorTableHandle>> applyLimit(ConnectorSession session, ConnectorTableHandle table, long limit)
{
PinotTableHandle handle = (PinotTableHandle) table;
Optional<DynamicTable> dynamicTable = handle.getQuery();
if (handle.getLimit().isPresent() && handle.getLimit().getAsLong() <= limit) {
if (dynamicTable.isPresent()) {
// single split - limit already present in handle is enforced
return Optional.of(new LimitApplicationResult<>(handle, true, false));
}
return Optional.empty();
}
Optional<DynamicTable> dynamicTable = handle.getQuery();
if (dynamicTable.isPresent() &&
(dynamicTable.get().getLimit().isEmpty() || dynamicTable.get().getLimit().getAsLong() > limit)) {
dynamicTable = Optional.of(new DynamicTable(dynamicTable.get().getTableName(),
Expand Down