Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Add explicit hints #7418

Merged
merged 4 commits into from
Nov 1, 2024
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 @@ -69,7 +69,7 @@ public FullQuery getLatestRowQuery(byte[] row, long ts, ColumnSelection columns,
@Override
public FullQuery getLatestRowsQuery(Iterable<byte[]> rows, long ts, ColumnSelection columns, boolean includeValue) {
String query = "SELECT"
+ " /*+ USE_NL(t m) LEADING(t m) */ "
+ " /*+ USE_NL(t m) LEADING(t m) NO_INDEX_FFS(m) */ "
+ " m.row_name, m.col_name, max(m.ts) as ts "
+ " FROM " + tableName + " m, TABLE(CAST(? AS " + structArrayPrefix() + "CELL_TS_TABLE)) t "
+ " WHERE m.row_name = t.row_name "
Expand Down Expand Up @@ -115,7 +115,7 @@ public FullQuery getAllRowQuery(byte[] row, long ts, ColumnSelection columns, bo
public FullQuery getAllRowsQuery(Iterable<byte[]> rows, long ts, ColumnSelection columns, boolean includeValue) {
String query = " /* GET_ALL_ROWS_SINGLE_BOUND (" + tableName + ") */ "
+ " SELECT"
+ " /*+ USE_NL(t m) LEADING(t m) */"
+ " /*+ USE_NL(t m) LEADING(t m) NO_INDEX_FFS(m) */"
+ " m.row_name, m.col_name, m.ts" + getValueSubselect("m", includeValue)
+ " FROM " + tableName + " m, TABLE(CAST(? AS " + structArrayPrefix() + "CELL_TS_TABLE)) t "
+ " WHERE m.row_name = t.row_name "
Expand Down Expand Up @@ -149,7 +149,7 @@ public FullQuery getLatestCellQuery(Cell cell, long ts, boolean includeValue) {
@Override
public FullQuery getLatestCellsQuery(Collection<Map.Entry<Cell, Long>> cells, boolean includeValue) {
String query = "SELECT"
+ " /*+ USE_NL(t m) LEADING(t m) */ "
+ " /*+ USE_NL(t m) LEADING(t m) NO_INDEX_FFS(m) */ "
+ " m.row_name, m.col_name, max(m.ts) as ts "
+ " FROM " + tableName + " m, TABLE(CAST(? AS " + structArrayPrefix() + "CELL_TS_TABLE)) t "
+ " WHERE m.row_name = t.row_name "
Expand All @@ -176,7 +176,7 @@ public FullQuery getAllCellQuery(Cell cell, long ts, boolean includeValue) {
public FullQuery getAllCellsQuery(Iterable<Cell> cells, long ts, boolean includeValue) {
String query = " /* GET_ALL_CELLS_SINGLE_BOUND (" + tableName + ") */ "
+ " SELECT"
+ " /*+ USE_NL(t m) LEADING(t m) */ "
+ " /*+ USE_NL(t m) LEADING(t m) NO_INDEX_FFS(m) */ "
+ " m.row_name, m.col_name, m.ts" + getValueSubselect("m", includeValue)
+ " FROM " + tableName + " m, TABLE(CAST(? AS " + structArrayPrefix() + "CELL_TS_TABLE)) t "
+ " WHERE m.row_name = t.row_name "
Expand Down Expand Up @@ -277,7 +277,7 @@ protected FullQuery getRowsColumnRangeSubQuery(
protected FullQuery getRowsColumnRangeFullyLoadedRowsSubQuery(
List<byte[]> rows, long ts, ColumnRangeSelection columnRangeSelection) {
String query = "SELECT"
+ " /*+ USE_NL(t m) LEADING(t m) */"
+ " /*+ USE_NL(t m) LEADING(t m) NO_INDEX_FFS(m) */"
+ " m.row_name, m.col_name, max(m.ts) as ts"
+ " FROM " + tableName + " m, TABLE(CAST(? AS " + structArrayPrefix() + "CELL_TS_TABLE)) t "
+ " WHERE m.row_name = t.row_name "
Expand All @@ -297,15 +297,15 @@ protected FullQuery getRowsColumnRangeFullyLoadedRowsSubQuery(
return fullQuery;
}

private String wrapQueryWithIncludeValue(String wrappedName, String query, boolean includeValue) {
private String wrapQueryWithIncludeValue(String name, String query, boolean includeValue) {
if (!includeValue) {
return query;
return "/* " + name + " (" + tableName + ") */ " + query;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This ensures that if includeValue is not set, the sql statement still gets a "name".

}
return " /* " + wrappedName + " (" + tableName + ") */ "
return "/* " + name + "_VALUE (" + tableName + ") */ "
+ " SELECT"
+ " /*+ USE_NL(i wrap) LEADING(i wrap) NO_MERGE(i) NO_PUSH_PRED(i)"
+ " INDEX(wrap " + PrimaryKeyConstraintNames.get(tableName) + ") */ "
+ " wrap.row_name, wrap.col_name, wrap.ts" + getValueSubselect("wrap", includeValue)
+ " wrap.row_name, wrap.col_name, wrap.ts" + getValueSubselect("wrap", true)
+ " FROM " + tableName + " wrap, ( " + query + " ) i "
+ " WHERE wrap.row_name = i.row_name "
+ " AND wrap.col_name = i.col_name "
Expand Down
7 changes: 7 additions & 0 deletions changelog/@unreleased/pr-7418.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type: fix
fix:
description: |-
Add explicit hints, have seen Oracle incorrectly using FAST_FULL_SCAN on very large tables.
Possibly unexpected side effect from https://github.com/palantir/atlasdb/pull/7338 - even though the cardinality hints removed were misleading, they may have made Oracle behave.
links:
- https://github.com/palantir/atlasdb/pull/7418