Skip to content
Merged
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 @@ -1069,14 +1069,14 @@ public List<Interval> retrieveUnusedSegmentIntervals(
* guarantee on the order of intervals in the list or on whether the limited
* list contains the earliest or latest intervals present in the datasource.
*
* @return List of unused segment intervals containing upto {@code limit} entries.
* @return List of unused segment intervals containing upto {@code limit} interval entries.
*/
public List<Interval> retrieveUnusedSegmentIntervals(String dataSource, int limit)
{
final String sql = StringUtils.format(
"SELECT start, %2$send%2$s FROM %1$s"
+ " WHERE dataSource = :dataSource AND used = false"
+ " GROUP BY start, %2$send%2$s"
+ " GROUP BY %2$send%2$s, start"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

could this implicitly change any ordering assumptions of the output?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caller typically should not assume any order of the output as the method does not guarantee any order anyway.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The reason I mentioned it was for safety, since in this I attempted doing something similar (on a different query though) and saw perf gains as well.

@cryptoe cryptoe Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

+1 @kfaraz comment.
We should not assume any ordering guarantees.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: may want an inline comment that explicitly states that the group by ordering is being done so we select an index to avoid regression in future (unlikely but possible)

+ " %3$s",
dbTables.getSegmentsTable(), connector.getQuoteString(), connector.limitClause(limit)
);
Expand Down
Loading