Пример #1
0
    def _setIndexedCols(self):
        '''Decides which fields must be indexed, based on key and index
        information.'''
        #Find all columns that are indexed or unique indexed
        uniq = self.sqlDb.inspector.get_unique_constraints(self.tableName)
        idx = self.sqlDb.inspector.get_indexes(self.tableName)
        #Only single-field constraints will be carried over as such
        uniqCols = [x['column_names'] for x in uniq \
                    if len(x['column_names']) == 1]
        idxCols = [x['column_names'] for x in idx]
        idxCols.extend([x['column_names'] for x in uniq \
                        if len(x['column_names']) != 1])
        #Don't forget primary key constraint
        if len(self.pkCols) == 1:
            uniqCols.append(self.pkCols.keys())
        else:
            idxCols.append(self.pkCols.keys())

        uniqColNames = listUnique(listFlatten(uniqCols))
        #Remove unique constrained columns from columns to be indexed
        idxColNames = listSubtract(listUnique(listFlatten(idxCols)),
                                   uniqColNames)
        self.uniqCols = [self.cols[x] for x in uniqColNames]
        #Redundant fields are excluded
        if REMOVE_REDUNDANT_FIELDS:
            self.idxCols = [self.cols[x] for x in idxColNames \
                            if not self.cols[x].isRedundant()]
        else:
            self.idxCols = [self.cols[x] for x in idxColNames]
        LOG.debug("Unique constraints on table %s, columns %s" %
                  (self.tableName, str([x.name for x in self.uniqCols])))
        LOG.debug("Indexes on table %s, columns %s" %
                  (self.tableName, str([x.name for x in self.idxCols])))
Пример #2
0
    def _setIndexedCols(self):
        """Decides which fields must be indexed, based on key and index
        information."""
        # Find all columns that are indexed or unique indexed
        uniq = self.sqlDb.inspector.get_unique_constraints(self.tableName)
        idx = self.sqlDb.inspector.get_indexes(self.tableName)
        # Only single-field constraints will be carried over as such
        uniqCols = [x["column_names"] for x in uniq if len(x["column_names"]) == 1]
        idxCols = [x["column_names"] for x in idx]
        idxCols.extend([x["column_names"] for x in uniq if len(x["column_names"]) != 1])
        # Don't forget primary key constraint
        if len(self.pkCols) == 1:
            uniqCols.append(self.pkCols.keys())
        else:
            idxCols.append(self.pkCols.keys())

        uniqColNames = listUnique(listFlatten(uniqCols))
        # Remove unique constrained columns from columns to be indexed
        idxColNames = listSubtract(listUnique(listFlatten(idxCols)), uniqColNames)
        self.uniqCols = [self.cols[x] for x in uniqColNames]
        # Redundant fields are excluded
        if REMOVE_REDUNDANT_FIELDS:
            self.idxCols = [self.cols[x] for x in idxColNames if not self.cols[x].isRedundant()]
        else:
            self.idxCols = [self.cols[x] for x in idxColNames]
        LOG.debug("Unique constraints on table %s, columns %s" % (self.tableName, str([x.name for x in self.uniqCols])))
        LOG.debug("Indexes on table %s, columns %s" % (self.tableName, str([x.name for x in self.idxCols])))
Пример #3
0
 def _ensureUniqRelTypes(self):
     """There may be synonym relation types refering to different foreign
     keys or even different many-to-many tables. Here we will ensure that
     this will not happen. IMPORTANT:This should be called only after all
     foreign keys have been instantiated."""
     # Get all objects that will be imported as relationships
     m2mTables = [tbl for tbl in self.tables.values() if tbl.isManyToMany()]
     allFKeys = [tbl.fKeys for tbl in self.tables.values() if not tbl.isManyToMany()]
     allRelObjects = listFlatten(allFKeys)
     allRelObjects.extend(m2mTables)
     for i, (obj1, obj2) in enumerate(combinations(allRelObjects, 2)):
         assert hasattr(obj1, "relType") and hasattr(obj2, "relType")
         if obj1.relType == obj2.relType:
             # Silly, but it works
             obj1.relType = obj1.relType + str(i * 2)
             obj2.relType = obj2.relType + str(i * 2 + 1)
Пример #4
0
 def _ensureUniqRelTypes(self):
     '''There may be synonym relation types refering to different foreign
     keys or even different many-to-many tables. Here we will ensure that
     this will not happen. IMPORTANT:This should be called only after all
     foreign keys have been instantiated.'''
     #Get all objects that will be imported as relationships
     m2mTables = [tbl for tbl in self.tables.values() \
                  if tbl.isManyToMany()]
     allFKeys = [tbl.fKeys for tbl in self.tables.values() \
                  if not tbl.isManyToMany()]
     allRelObjects = listFlatten(allFKeys)
     allRelObjects.extend(m2mTables)
     for i, (obj1, obj2) in enumerate(combinations(allRelObjects, 2)):
         assert hasattr(obj1, 'relType') and \
             hasattr(obj2, 'relType')
         if obj1.relType == obj2.relType:
             #Silly, but it works
             obj1.relType = obj1.relType + str(i * 2)
             obj2.relType = obj2.relType + str(i * 2 + 1)