DaveBirdsall commented on a change in pull request #1846: [TRAFODION-3314] 
Avoid generating redundant DDL in OSIM for unique constraints
URL: https://github.com/apache/trafodion/pull/1846#discussion_r299677737
 
 

 ##########
 File path: core/sql/optimizer/OptimizerSimulator.cpp
 ##########
 @@ -541,31 +541,43 @@ void OptimizerSimulator::dumpDDLs(const QualifiedName & 
qualifiedName)
                                    <<"."<< qualifiedName.getSchemaName() 
                                    << ";" << endl;
         
+        // skippingSystemGeneratedIndex is set to TRUE to avoid generating 
redundant
+        // DDL for system-generated indexes
+        NABoolean skippingSystemGeneratedIndex = FALSE;
         outQueue->position();//rewind
         for (int i = 0; i < outQueue->numEntries(); i++) {
             OutputInfo * vi = (OutputInfo*)outQueue->getNext();
             char * ptr = vi->get(0);
-            // skip heading newline, and add a comment line
-            // for the DDL text upto the first trailing '\n'
-            Int32 ix = 0;
-            for(; ptr[ix]=='\n'; ix++);
-            if( strstr(ptr, "CREATE TABLE") ||
-                strstr(ptr, "CREATE INDEX") ||
-                strstr(ptr, "CREATE UNIQUE INDEX") ||
-                strstr(ptr, "ALTER TABLE")  )
+            if (strcmp(ptr,"\n-- The following index is a system created index 
--") == 0)
+              skippingSystemGeneratedIndex = TRUE;
 
+            if (!skippingSystemGeneratedIndex)
             {
-              (*createTable) << "--";
-              char* x = ptr+ix;
-              while ( (*x) && *x != '\n' ) {
-                (*createTable) << *x;
-                x++;
-              } 
-              (*createTable) << endl;
+                // skip heading newline, and add a comment line
+                // for the DDL text upto the first trailing '\n'
+                Int32 ix = 0;
+                for(; ptr[ix]=='\n'; ix++);
+                if( strstr(ptr, "CREATE TABLE") ||
+                    strstr(ptr, "CREATE INDEX") ||
+                    strstr(ptr, "CREATE UNIQUE INDEX") ||
+                    strstr(ptr, "ALTER TABLE")  )
+
+                {
+                  (*createTable) << "--";
+                  char* x = ptr+ix;
+                  while ( (*x) && *x != '\n' ) {
+                    (*createTable) << *x;
+                    x++;
+                  } 
+                  (*createTable) << endl;
+                }
+
+                //output ddl  
+                (*createTable) << ptr << endl;
             }
 
-            //output ddl    
-            (*createTable) << ptr << endl;
+            if (skippingSystemGeneratedIndex && (strcmp(ptr,";") == 0)) // at 
end of DDL to be skipped?
+              skippingSystemGeneratedIndex = FALSE;
 
 Review comment:
   Note to reviewers: The code from lines 556 through 576 in the new file is 
merely re-indented lines 548 through 568 from the old file, with an "if 
(!skippingSystemGenerated) { ... }" around it. Unfortunately the comparison 
tool doesn't render this difference nicely.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to