vldpyatkov commented on code in PR #13366:
URL: https://github.com/apache/ignite/pull/13366#discussion_r3757226704
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/prepare/PrepareServiceImpl.java:
##########
@@ -136,6 +154,311 @@ public PrepareServiceImpl(GridKernalContext ctx) {
}
}
+ /**
+ * Prepares a {@code SELECT ... FOR UPDATE} statement.
+ *
+ * <p>Steps:
+ * <ol>
+ * <li>Unwrap optional ORDER BY and validate that the inner query is a
plain {@link SqlSelect}
+ * (not UNION etc.).</li>
+ * <li>Collect and validate cache-based tables from the FROM clause.</li>
+ * <li>Append OF columns for validation and lock columns for every
table.</li>
+ * <li>Prepare the modified SELECT as a normal {@link
MultiStepQueryPlan}.</li>
+ * <li>Resolve tables selected by OF using aliases and validated column
origins.</li>
+ * <li>Return a {@link SelectForUpdatePlan} wrapping the inner plan.</li>
+ * </ol>
+ */
+ private SelectForUpdatePlan
prepareSelectForUpdate(IgniteSqlSelectForUpdate forUpdate, PlanningContext ctx)
+ throws ValidationException {
+ SqlNode innerQry = forUpdate.query();
+
+ SqlOrderBy orderBy = null;
+
+ if (innerQry instanceof SqlOrderBy) {
+ orderBy = (SqlOrderBy)innerQry;
+ innerQry = orderBy.query;
+ }
+
+ if (!(innerQry instanceof SqlSelect))
+ throw new IgniteSQLException(
+ "SELECT FOR UPDATE is only supported for plain SELECT
statements",
+ IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
+
+ SqlSelect select = (SqlSelect)innerQry;
+ SqlNodeList orderList = orderBy == null ? select.getOrderList() :
orderBy.orderList;
+ SqlNode offset = orderBy == null ? select.getOffset() : orderBy.offset;
+ SqlNode fetch = orderBy == null ? select.getFetch() : orderBy.fetch;
+
+ validateSelectForUpdateShape(select, orderList, ctx.planner());
+
+ // Unwrap optional AS alias around the table reference.
+ SqlNode from = select.getFrom();
+
+ if (from == null)
+ throw new IgniteSQLException(
+ "SELECT FOR UPDATE requires a FROM clause",
+ IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
+
+ List<TableRef> tableRefs = new ArrayList<>();
Review Comment:
And we allow users to get a deadlock on tables, do we?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]