SourabhBadhya commented on code in PR #4313:
URL: https://github.com/apache/hive/pull/4313#discussion_r1219121485
##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/CompactionTxnHandler.java:
##########
@@ -92,6 +94,52 @@ class CompactionTxnHandler extends TxnHandler {
"DELETE FROM \"TXNS\" WHERE \"TXN_ID\" NOT IN (SELECT \"TC_TXNID\" FROM
\"TXN_COMPONENTS\") " +
"AND (\"TXN_STATE\" = " + TxnStatus.ABORTED + " OR \"TXN_STATE\" = "
+ TxnStatus.COMMITTED + ") " +
"AND \"TXN_ID\" < ?";
+
+ // Three inner sub-queries which are under union all and gets the max values
for corresponding db, table, partition.
+ private static final String SELECT_ABORTS_WITH_MIN_OPEN_WRITETXN_QUERY =
+ "SELECT \"DB\", \"TBL\", \"PART\", MAX(\"MIN_TXN_START_TIME\"),
MAX(\"ABORTED_TXN_COUNT\"), " +
+ " MAX(\"MIN_OPEN_WRITE_TXNID\"), MAX(\"RETRY_RETENTION\"),
MAX(\"RETRY_RECORD_CHECK\") FROM ( " +
+ // First sub-query - Gets the aborted txns with min txn start time,
number of aborted txns
+ // for corresponding db, table, partition.
+ " SELECT \"TC_DATABASE\" AS \"DB\", \"TC_TABLE\" AS \"TBL\",
\"TC_PARTITION\" AS \"PART\", " +
+ " MIN(\"TXN_STARTED\") AS \"MIN_TXN_START_TIME\", COUNT(*) AS
\"ABORTED_TXN_COUNT\", " +
+ " 0 AS \"MIN_OPEN_WRITE_TXNID\", -1 AS \"RETRY_RETENTION\", 0 AS
\"RETRY_RECORD_CHECK\" " +
Review Comment:
As discussed, implemented a left join query rather than union all since
union all based query can fetch large number of records in the result set when
there are no aborted txns for a table/partition. Done.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]