Repository: incubator-trafodion
Updated Branches:
  refs/heads/master f9b3afd33 -> 2a9e9f223


Changes to drop LOB dependent tables during drop schema. TRAFODION-1883.


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/cf5390e7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/cf5390e7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/cf5390e7

Branch: refs/heads/master
Commit: cf5390e7d6f59257529668361e98325c5bbf8f9b
Parents: 57d3ebd
Author: Sandhya Sundaresan <sandhyasun@edev03.esgyn.local>
Authored: Tue Mar 15 18:10:11 2016 +0000
Committer: Sandhya Sundaresan <sandhyasun@edev03.esgyn.local>
Committed: Tue Mar 15 18:10:11 2016 +0000

----------------------------------------------------------------------
 core/sql/cli/Cli.cpp                     |  2 +-
 core/sql/common/ComSmallDefs.h           |  4 +-
 core/sql/exp/ExpLOB.cpp                  | 16 ++---
 core/sql/sqlcomp/CmpSeabaseDDL.h         |  2 +-
 core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp | 11 ++++
 core/sql/sqlcomp/CmpSeabaseDDLschema.cpp | 84 ++++++++++++++++++++-------
 core/sql/sqlcomp/CmpSeabaseDDLtable.cpp  |  9 +--
 7 files changed, 92 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/cf5390e7/core/sql/cli/Cli.cpp
----------------------------------------------------------------------
diff --git a/core/sql/cli/Cli.cpp b/core/sql/cli/Cli.cpp
index 58a77ba..f197018 100644
--- a/core/sql/cli/Cli.cpp
+++ b/core/sql/cli/Cli.cpp
@@ -2454,7 +2454,7 @@ Lng32 SQLCLI_ProcessRetryQuery(
             return retcode;
         }
 
-      if (rootTdb->updDelInsertQuery())
+      if (rootTdb->updDelInsertQuery()|| (rootTdb->ddlQuery()))
         {
           if (rootTdb->transactionReqd() &&
               (NOT exTransaction->xnInProgress()))

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/cf5390e7/core/sql/common/ComSmallDefs.h
----------------------------------------------------------------------
diff --git a/core/sql/common/ComSmallDefs.h b/core/sql/common/ComSmallDefs.h
index 9a10fc8..630d292 100644
--- a/core/sql/common/ComSmallDefs.h
+++ b/core/sql/common/ComSmallDefs.h
@@ -122,7 +122,9 @@ typedef NABoolean               ComBoolean;
 #define SEABASE_OLD_PRIVMGR_SCHEMA         "PRIVMGR_MD"
 #define SEABASE_PRIVMGR_SCHEMA         "_PRIVMGR_MD_"
 #define SEABASE_UDF_SCHEMA             "_UDF_"
-
+#define LOB_MD_PREFIX                  "LOBMD_"
+#define LOB_DESC_CHUNK_PREFIX          "LOBDescChunks_"
+#define LOB_DESC_HANDLE_PREFIX         "LOBDescHandle_"
 #define SEABASE_DEFAULT_COL_FAMILY "#1"
 
 // reserved names for seabase metadata where SQL table information is kept

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/cf5390e7/core/sql/exp/ExpLOB.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/ExpLOB.cpp b/core/sql/exp/ExpLOB.cpp
index 18470d6..556907c 100644
--- a/core/sql/exp/ExpLOB.cpp
+++ b/core/sql/exp/ExpLOB.cpp
@@ -94,7 +94,7 @@ char * ExpLOBoper::ExpGetLOBDescHandleObjNamePrefix(Int64 uid,
   if (outBufLen < 512)
     return NULL;
   
-  str_sprintf(outBuf, "LOBDescHandle_%020Ld", uid);
+  str_sprintf(outBuf, "%s_%020Ld", LOB_DESC_HANDLE_PREFIX,uid);
   
   return outBuf;
 }
@@ -107,8 +107,8 @@ char * ExpLOBoper::ExpGetLOBDescHandleName(Lng32 
schNameLen, char * schName,
       (schName == NULL))
     return NULL;
   
-  str_sprintf(outBuf, "%s.\"LOBDescHandle_%020Ld_%04d\"",
-             schName, uid, num);
+  str_sprintf(outBuf, "%s.\"%s_%020Ld_%04d\"",
+             schName, LOB_DESC_HANDLE_PREFIX,uid, num);
   
   return outBuf;
 }
@@ -116,7 +116,7 @@ char * ExpLOBoper::ExpGetLOBDescHandleName(Lng32 
schNameLen, char * schName,
 Lng32 ExpLOBoper::ExpGetLOBnumFromDescName(char * descName, Lng32 descNameLen)
 {
   // Desc Name Format: LOBDescHandle_%020Ld_%04d
-  char * lobNumPtr = &descName[strlen("LOBDescHandle_") + 20 + 1];
+  char * lobNumPtr = &descName[sizeof(LOB_DESC_HANDLE_PREFIX) + 20 + 1];
   Lng32 lobNum = str_atoi(lobNumPtr, 4);
   
   return lobNum;
@@ -131,8 +131,8 @@ char * ExpLOBoper::ExpGetLOBDescChunksName(Lng32 
schNameLen, char * schName,
       (schName == NULL))
     return NULL;
   
-  str_sprintf(outBuf, "%s.\"LOBDescChunks_%020Ld_%04d\"",
-             schName, uid, num);
+  str_sprintf(outBuf, "%s.\"%s_%020Ld_%04d\"",
+             schName, LOB_DESC_CHUNK_PREFIX,uid, num);
 
   return outBuf;
 }
@@ -159,8 +159,8 @@ char * ExpLOBoper::ExpGetLOBMDName(Lng32 schNameLen, char * 
schName,
   if (outBufLen < 512)
     return NULL;
 
-  str_sprintf(outBuf, "%s.\"LOBMD_%020Ld\"",
-             schName, uid);
+  str_sprintf(outBuf, "%s.\"%s_%020Ld\"",
+             schName, LOB_MD_PREFIX,uid);
 
   return outBuf;
 }

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/cf5390e7/core/sql/sqlcomp/CmpSeabaseDDL.h
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDL.h b/core/sql/sqlcomp/CmpSeabaseDDL.h
index e1eee25..b51df70 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDL.h
+++ b/core/sql/sqlcomp/CmpSeabaseDDL.h
@@ -162,7 +162,7 @@ class CmpSeabaseDDL
   static NABoolean isHbase(const NAString &catName);
 
   static bool isHistogramTable(const NAString &tabName);
-
+  static NABoolean isLOBDependentNameMatch(const NAString &name);
   static NABoolean isSeabaseMD(const NAString &catName,
                               const NAString &schName,
                               const NAString &objName);

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/cf5390e7/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp 
b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
index 938d8f2..1efa24d 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLcommon.cpp
@@ -926,6 +926,17 @@ bool CmpSeabaseDDL::isHistogramTable(const NAString &name)
 
 }
 
+NABoolean CmpSeabaseDDL::isLOBDependentNameMatch(const NAString &name)
+{
+  if ((name(0,min((sizeof(LOB_MD_PREFIX)-1), name.length())) == LOB_MD_PREFIX) 
||
+      (name(0,min((sizeof(LOB_DESC_CHUNK_PREFIX)-1), 
name.length()))==LOB_DESC_CHUNK_PREFIX)||
+      (name(0,min((sizeof(LOB_DESC_HANDLE_PREFIX)-1), 
name.length()))==LOB_DESC_HANDLE_PREFIX)
+      )
+    return true;
+  else
+    return false;
+}
+
 NABoolean CmpSeabaseDDL::isSeabase(const NAString &catName)
 {
   if ((CmpCommon::getDefault(MODE_SEABASE) == DF_ON) &&

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/cf5390e7/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp 
b/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp
index 34a8cf0..dc13462 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLschema.cpp
@@ -61,6 +61,7 @@ static bool dropOneTable(
    const char * schemaName, 
    const char * objectName,
    bool isVolatile,
+   bool ifExists,
    bool ddlXns);
    
 static bool transferObjectPrivs(
@@ -499,6 +500,8 @@ void CmpSeabaseDDL::dropSeabaseSchema(StmtDDLDropSchema * 
dropSchemaNode)
 
    // select objects in the schema to drop, don't return 
PRIMARY_KEY_CONSTRAINTS,
    // they always get removed when the parent table is dropped.
+   // Filter out the LOB depenedent tables too - they will get dropped when 
+   //the main LOB table is dropped. 
    str_sprintf(query,"SELECT TRIM(object_name), TRIM(object_type) "
                      "FROM %s.\"%s\".%s "
                      "WHERE catalog_name = '%s' AND schema_name = '%s' AND "
@@ -548,7 +551,7 @@ void CmpSeabaseDDL::dropSeabaseSchema(StmtDDLDropSchema * 
dropSchemaNode)
        dirtiedMetadata = TRUE;
        if (dropOneTable(cliInterface,(char*)catName.data(),
                         (char*)schName.data(),(char*)objName.data(),
-                        isVolatile, dropSchemaNode->ddlXns()))
+                        isVolatile, FALSE,dropSchemaNode->ddlXns()))
           someObjectsCouldNotBeDropped = true;
      }
    }
@@ -638,26 +641,58 @@ void CmpSeabaseDDL::dropSeabaseSchema(StmtDDLDropSchema * 
dropSchemaNode)
 
    objectsQueue->position();
    for (int idx = 0; idx < objectsQueue->numEntries(); idx++)
-   {
-      OutputInfo * vi = (OutputInfo*)objectsQueue->getNext(); 
+     {
+       OutputInfo * vi = (OutputInfo*)objectsQueue->getNext(); 
 
-      NAString objName = vi->get(0);
-      NAString objType = vi->get(1);
+       NAString objName = vi->get(0);
+       NAString objType = vi->get(1);
+
+       // drop user objects first
+       if (objType == COM_BASE_TABLE_OBJECT_LIT) 
+        {
+          // histogram tables have already been dropped
+          // Avoid any tables that match LOB dependent tablenames.
+          // (there is no special type for these tables) 
+          if (!isHistogramTable(objName) && !isLOBDependentNameMatch(objName))
+            {
+              dirtiedMetadata = TRUE;
+              if (dropOneTable(cliInterface,(char*)catName.data(), 
+                               (char*)schName.data(),(char*)objName.data(),
+                               isVolatile, FALSE,dropSchemaNode->ddlXns()))
+                someObjectsCouldNotBeDropped = true;
+            }
+        } 
+     } 
+
+   // If there are any user tables having the LOB dependent name pattern, they
+   // will still be around. Drop those. The real LOB dependent tables, would
+   //have been dropped in the previous step 
+  
 
-      // drop user objects first
-      if (objType == COM_BASE_TABLE_OBJECT_LIT)
-      {
-         // histogram tables have already been dropped
-         if (!isHistogramTable(objName))
-         {
-            dirtiedMetadata = TRUE;
-            if (dropOneTable(cliInterface,(char*)catName.data(), 
-                             (char*)schName.data(),(char*)objName.data(),
-                             isVolatile, dropSchemaNode->ddlXns()))
-               someObjectsCouldNotBeDropped = true;
-         }
-      } 
-   } 
+    objectsQueue->position();
+   for (int idx = 0; idx < objectsQueue->numEntries(); idx++)
+     {
+       OutputInfo * vi = (OutputInfo*)objectsQueue->getNext(); 
+
+       NAString objName = vi->get(0);
+       NAString objType = vi->get(1);
+
+       if (objType == COM_BASE_TABLE_OBJECT_LIT)
+        {
+          if (!isHistogramTable(objName) && isLOBDependentNameMatch(objName))
+            {
+              dirtiedMetadata = TRUE;
+              // Pass in TRUE for "ifExists" since the lobDependent tables 
+              // would have already been dropped and we don't want those to 
+              // raise errors. We just want to catch any user tables that 
+              // happen to have the same name patterns.
+              if (dropOneTable(cliInterface,(char*)catName.data(), 
+                               (char*)schName.data(),(char*)objName.data(),
+                               isVolatile,TRUE, dropSchemaNode->ddlXns()))
+                someObjectsCouldNotBeDropped = true;
+            }
+        } 
+     } 
  
    // Drop any remaining indexes.
 
@@ -1151,6 +1186,7 @@ static bool dropOneTable(
    const char * schemaName, 
    const char * objectName,
    bool isVolatile,
+   bool ifExists,
    bool ddlXns)
    
 {
@@ -1160,17 +1196,23 @@ char buf [1000];
 bool someObjectsCouldNotBeDropped = false;
 
 char volatileString[20] = {0};
+ char ifExistsString[20] = {0};
 Lng32 cliRC = 0;
 
+
+
    if (isVolatile)
       strcpy(volatileString,"VOLATILE");
 
+   if (ifExists)
+     strcpy(ifExistsString,"IF EXISTS");
+
    if (ComIsTrafodionExternalSchemaName(schemaName))
      str_sprintf(buf,"DROP EXTERNAL TABLE \"%s\" FOR \"%s\".\"%s\".\"%s\" 
CASCADE",
                  objectName,catalogName,schemaName,objectName);
    else
-     str_sprintf(buf,"DROP %s TABLE \"%s\".\"%s\".\"%s\" CASCADE",
-                 volatileString,catalogName,schemaName,objectName);
+     str_sprintf(buf,"DROP %s %s TABLE  \"%s\".\"%s\".\"%s\" CASCADE",
+                 volatileString, ifExistsString, 
catalogName,schemaName,objectName);
  
 ULng32 savedParserFlags = Get_SqlParser_Flags(0xFFFFFFFF);
 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/cf5390e7/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp 
b/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
index fb9c802..a4b74e3 100644
--- a/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
+++ b/core/sql/sqlcomp/CmpSeabaseDDLtable.cpp
@@ -2226,6 +2226,7 @@ short CmpSeabaseDDL::createSeabaseTable2(
   Int64 lobMaxSize =  CmpCommon::getDefaultNumeric(LOB_MAX_SIZE)*1024*1024;
   if (j > 0)
     {
+      Int32 rc = sendAllControls(FALSE, FALSE, TRUE);
       //if the table is a volatile table return an error
       if (createTableNode->isVolatile())
         {
@@ -2247,7 +2248,7 @@ short CmpSeabaseDDL::createSeabaseTable2(
       newSchName.append("\".\"");
       newSchName.append(schemaNamePart);
       newSchName += "\"";
-      Lng32 rc = SQL_EXEC_LOBddlInterface((char*)newSchName.data(),
+       rc = SQL_EXEC_LOBddlInterface((char*)newSchName.data(),
                                           newSchName.length(),
                                           objUID,
                                           j,
@@ -3334,8 +3335,7 @@ short CmpSeabaseDDL::dropSeabaseTable2(
           processReturn();
           
           return -1;
-        }
-      
+        }     
     }
 
   // drop all check constraints from metadata if 'no check' is not specified.
@@ -3582,6 +3582,7 @@ short CmpSeabaseDDL::dropSeabaseTable2(
     }
   if (j > 0)
     {
+      Int32 rc = sendAllControls(FALSE, FALSE, TRUE);
       Int64 objUID = getObjectUID(cliInterface,
                                  catalogNamePart.data(), 
schemaNamePart.data(), 
                                  objectNamePart.data(),
@@ -3592,7 +3593,7 @@ short CmpSeabaseDDL::dropSeabaseTable2(
       newSchName.append("\".\"");
       newSchName.append(schemaNamePart);
       newSchName += "\"";
-      Lng32 rc = SQL_EXEC_LOBddlInterface((char*)newSchName.data(),
+      rc = SQL_EXEC_LOBddlInterface((char*)newSchName.data(),
                                          newSchName.length(),
                                          objUID,
                                          j,

Reply via email to