[ 
https://issues.apache.org/jira/browse/HIVE-24663?focusedWorklogId=599891&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-599891
 ]

ASF GitHub Bot logged work on HIVE-24663:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 20/May/21 15:52
            Start Date: 20/May/21 15:52
    Worklog Time Spent: 10m 
      Work Description: deniskuzZ commented on a change in pull request #2266:
URL: https://github.com/apache/hive/pull/2266#discussion_r636228265



##########
File path: 
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java
##########
@@ -5390,6 +5406,493 @@ public void countOpenTxns() throws MetaException {
     }
   }
 
+  private void cleanOldStatsFromPartColStatTable(Map<String, PartitionInfo> 
statsPartInfoMap,
+                                                 Map<String, ColumnStatistics> 
newStatsMap,
+                                                 Connection dbConn) throws 
SQLException {
+    PreparedStatement statementDelete = null;
+    int numRows = 0;
+    int maxNumRows = MetastoreConf.getIntVar(conf, 
ConfVars.DIRECT_SQL_MAX_ELEMENTS_VALUES_CLAUSE);
+    String delete = "DELETE FROM \"PART_COL_STATS\" where \"PART_ID\" = ? AND 
\"COLUMN_NAME\" = ?";
+
+    try {
+      statementDelete = dbConn.prepareStatement(delete);
+      for (Map.Entry entry : newStatsMap.entrySet()) {
+        // If the partition does not exist (deleted/removed by some other 
task), no need to update the stats.
+        if (!statsPartInfoMap.containsKey(entry.getKey())) {
+          continue;
+        }
+
+        ColumnStatistics colStats = (ColumnStatistics) entry.getValue();
+        for (ColumnStatisticsObj statisticsObj : colStats.getStatsObj()) {
+          statementDelete.setLong(1, 
statsPartInfoMap.get(entry.getKey()).partitionId);
+          statementDelete.setString(2, statisticsObj.getColName());
+          numRows++;
+          statementDelete.addBatch();
+          if (numRows == maxNumRows) {
+            statementDelete.executeBatch();
+            numRows = 0;
+            LOG.info("Executed delete " + delete + " for numRows " + numRows);
+          }
+        }
+      }
+
+      if (numRows != 0) {
+        statementDelete.executeBatch();
+      }
+    } finally {
+      closeStmt(statementDelete);
+    }
+  }
+
+  private long getMaxCSId(Connection dbConn) throws SQLException {
+    Statement stmtInt = null;
+    ResultSet rsInt = null;
+    long maxCsId = 0;
+    try {
+      stmtInt = dbConn.createStatement();
+      while (maxCsId == 0) {
+        String query = "SELECT \"NEXT_VAL\" FROM \"SEQUENCE_TABLE\" WHERE 
\"SEQUENCE_NAME\"= "

Review comment:
       that would create lock on SEQUENCE_TABLE for the duration of the whole 
stats update operation. Won't it interfere with the regular flow? 
   




-- 
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 599891)
    Time Spent: 0.5h  (was: 20m)

> Batch process in ColStatsProcessor for partitions.
> --------------------------------------------------
>
>                 Key: HIVE-24663
>                 URL: https://issues.apache.org/jira/browse/HIVE-24663
>             Project: Hive
>          Issue Type: Improvement
>            Reporter: Rajesh Balamohan
>            Assignee: mahesh kumar behera
>            Priority: Major
>              Labels: performance, pull-request-available
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> When large number of partitions (>20K) are processed, ColStatsProcessor runs 
> into DB issues. 
> {{ db.setPartitionColumnStatistics(request);}} gets stuck for hours together 
> and in some cases postgres stops processing. 
> It would be good to introduce small batches for stats gathering in 
> ColStatsProcessor instead of bulk update.
> Ref: 
> https://github.com/apache/hive/blob/master/ql/src/java/org/apache/hadoop/hive/ql/stats/ColStatsProcessor.java#L181
> https://github.com/apache/hive/blob/master/ql/src/java/org/apache/hadoop/hive/ql/stats/ColStatsProcessor.java#L199



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to