Skip to content

fix(admin): order Oracle operation logs before applying the row limit (#7739) - #7758

Merged
Aias00 merged 1 commit into
apache:masterfrom
konlue:fix/oracle-log-selectlimit
Oct 19, 2026
Merged

Aias00 merged 1 commit into
apache:masterfrom
konlue:fix/oracle-log-selectlimit

Conversation

@konlue

@konlue konlue commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Fixes #7739.

Summary

The Oracle selectLimit statement limits rows with WHERE ROWNUM <= #{limit} in the same query block as ORDER BY operation_time desc. Oracle may apply the row limit before sorting, so the recent-operation list can return older rows and omit the newest N; the generic statement orders first and then applies LIMIT.

Modifications

  • Wrap the operator-filtered, descending query in an inner subquery and apply WHERE ROWNUM <= #{limit} in the outer query (Oracle's documented top-N form).
  • Add a statement-shape regression test resolved with databaseId="oracle".

Verifying this change

  • New OperationRecordLogSelectLimitSqlTest: under databaseId="oracle", asserts the SQL starts with the wrapped subquery, ORDER BY precedes ROWNUM, and ROWNUM <= ? plus the operator filter are present. Fails on the previous statement (which shows rownum before order by), passes with the fix.

  • Targeted test passes:

    ./mvnw -B -ntp -pl shenyu-admin test -Dtest=OperationRecordLogSelectLimitSqlTest

    1/1 green.

  • Checkstyle passes:

    ./mvnw -B -ntp -pl shenyu-admin checkstyle:check

    clean.

Notes

The configured limit and the per-operator filter are unchanged; only the evaluation order (filter/sort, then row limit) is corrected. The test pins MyBatis dialect selection locally; execution against a real Oracle instance is exercised by the repository's SQL matrix. This PR touches the same mapper file as the separate Oracle CONCAT fix, but a different statement.

@Aias00 Aias00 left a comment

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.

LGTM. Verified the claim, the rewrite and the surrounding statements.

Evidence

  • The bug is real in the current statement (operation-record-log-sqlmap.xml:58-67): where rownum <= #{limit} sits in the same query block as order by operation_time desc. Oracle assigns ROWNUM as rows are produced, so the row limit is applied to the unsorted scan and the ordering happens afterwards on those N rows — i.e. "the N oldest rows, then sorted", which is exactly the reported symptom.
  • The generic statement (:45-56) already orders and then limits, so this change makes Oracle consistent with the existing contract instead of introducing new semantics.
  • SELECT * FROM (SELECT ... ORDER BY ...) WHERE ROWNUM <= ? is Oracle's documented top-N form and needs no derived-table alias; the inner Base_Column_List keeps the result map intact through SELECT *.
  • Scope is clean: ROWNUM <= appears exactly once in the whole shenyu-admin mapper set (the other 40 Oracle occurrences are ROWNUM = 1 single-row existence lookups, where ordering is irrelevant), so there is no second statement left with the same defect.
  • <where> with a single optional <if> renders nothing when username is null, which matches the previous optional predicate.

Non-blocking

  1. parameterType="java.lang.Integer" while the statement binds #{username} is pre-existing and only works because the mapper method passes a Map through @Param. Since you are in the file, a comment (or the accurate parameterType) would stop the next reader from "fixing" it into a real bug. The same applies to the statement you copied the shape from.
  2. The test pins statement shape, which is the reasonable unit-level assertion here. If an Oracle container ever lands in CI, an insert-three-take-two assertion is the only thing that would also catch a semantic regression.

@Aias00
Aias00 merged commit 0c0dfb5 into apache:master Oct 19, 2026
61 of 63 checks passed
@Aias00 Aias00 added this to the 2.7.2 milestone Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Oracle operation-log list limits rows before ordering the latest records

2 participants