changliiu commented on code in PR #35042:
URL: https://github.com/apache/beam/pull/35042#discussion_r2114869392
##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/changestreams/dao/PartitionMetadataDao.java:
##########
@@ -178,47 +179,57 @@ public List<String> findAllTableIndexes() {
*
* @return the earliest partition watermark which is not in a {@link
State#FINISHED} state.
*/
- public @Nullable Timestamp getUnfinishedMinWatermark() {
+ public @Nullable Timestamp getUnfinishedMinWatermark(Optional<Timestamp>
since) {
+ Timestamp sinceTimestamp = since.orElse(Timestamp.MIN_VALUE);
Statement statement;
+ final String minWatermark = "min_watermark";
if (this.isPostgres()) {
statement =
Statement.newBuilder(
- "SELECT \""
+ "SELECT min(\""
+ COLUMN_WATERMARK
- + "\" FROM \""
+ + "\") as "
+ + minWatermark
+ + " FROM \""
+ metadataTableName
+ "\" WHERE \""
+ COLUMN_STATE
+ "\" != $1"
- + " ORDER BY \""
+ + " AND \""
+ COLUMN_WATERMARK
- + "\" ASC LIMIT 1")
+ + "\" >= $2")
.bind("p1")
.to(State.FINISHED.name())
+ .bind("p2")
+ .to(sinceTimestamp)
.build();
} else {
statement =
Statement.newBuilder(
- "SELECT "
+ "SELECT min("
Review Comment:
There is a discussion to replace "limit 1" using "min()" in order to better
use the index. I agree that two queries can have the same result. Please
re-open if you have strong opinion on this. Thank you!
--
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]