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

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

                Author: ASF GitHub Bot
            Created on: 03/Jul/20 06:37
            Start Date: 03/Jul/20 06:37
    Worklog Time Spent: 10m 
      Work Description: adesh-rao commented on a change in pull request #1109:
URL: https://github.com/apache/hive/pull/1109#discussion_r449401898



##########
File path: 
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/cache/SharedCache.java
##########
@@ -1870,6 +2228,122 @@ public void removePartitionsFromCache(String catName, 
String dbName, String tblN
     return parts;
   }
 
+  public List<SQLPrimaryKey> listCachedPrimaryKeys(String catName, String 
dbName, String tblName) {
+    List<SQLPrimaryKey> keys = new ArrayList<>();
+    try {
+      cacheLock.readLock().lock();
+      TableWrapper tblWrapper = 
tableCache.getIfPresent(CacheUtils.buildTableKey(catName, dbName, tblName));
+      if (tblWrapper != null) {
+        keys = tblWrapper.getPrimaryKeys();
+      }
+    } finally {
+      cacheLock.readLock().unlock();
+    }
+    return keys;
+  }
+
+  public List<SQLForeignKey> listCachedForeignKeys(String catName, String 
foreignDbName, String foreignTblName,
+                                                   String parentDbName, String 
parentTblName) {
+    List<SQLForeignKey> keys = new ArrayList<>();
+    try {
+      cacheLock.readLock().lock();
+      TableWrapper tblWrapper = 
tableCache.getIfPresent(CacheUtils.buildTableKey(catName, foreignDbName, 
foreignTblName));
+      if (tblWrapper != null) {
+        keys = tblWrapper.getForeignKeys();
+      }
+    } finally {
+      cacheLock.readLock().unlock();
+    }
+
+    // filter out required foreign keys based on parent db/tbl name
+    if (!StringUtils.isEmpty(parentTblName) && 
!StringUtils.isEmpty(parentDbName)) {

Review comment:
       Even if tblWrapper is null, keys will be empty list and hence an empty 
list will be returned. So this should be fine, right?
   
   In case we move it to above if block, and assuming the list is not-empty, we 
will keep the read lock on for a longer duration (though only in milliseconds 
or even less), that's why I added it below. 




----------------------------------------------------------------
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: 454299)
    Time Spent: 1.5h  (was: 1h 20m)

> [CachedStore] Cache table constraints in CachedStore
> ----------------------------------------------------
>
>                 Key: HIVE-22015
>                 URL: https://issues.apache.org/jira/browse/HIVE-22015
>             Project: Hive
>          Issue Type: Sub-task
>            Reporter: Daniel Dai
>            Assignee: Adesh Kumar Rao
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 1.5h
>  Remaining Estimate: 0h
>
> Currently table constraints are not cached. Hive will pull all constraints 
> from tables involved in query, which results multiple db reads (including 
> get_primary_keys, get_foreign_keys, get_unique_constraints, etc). The effort 
> to cache this is small as it's just another table component.



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

Reply via email to