Ejemplo n.º 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])))
Ejemplo n.º 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])))
Ejemplo n.º 3
0
 def _resolveForeignKeys(self):
     '''Links foreign keys to other tables. MUST be called AFTER all
     tables have been instantiated as TableInfo objects'''
     fkeycols = []
     self.fKeys = list()
     for fk in self._fKeysSA:
         self.fKeys.append(ForeignKeyInfo(fk, self))
         fkeycols.extend(fk['constrained_columns'])
     #Find all columns of the table that belong to some foreign key
     fkeycolsUniq = listUnique(fkeycols) if self._fKeysSA else list()
     self.fKeysCols = OrderedDict()
     for name in fkeycolsUniq:
         self.fKeysCols[name] = self.cols[name]
         self.cols[name].isFkCol = True
     #All tables this table refers to
     self.refTables = listUnique([k.refTable for k in self.fKeys])
     #Processes below can not be called earlier than that
     if self.isManyToMany():
         relType = "%s_%s" % (self.fKeys[0].refTable.labelName,
                              self.fKeys[1].refTable.labelName)
         #relType attribute is set ONLY for such tables
         self.relType = _transformRelTypes(relType)
     if REMOVE_REDUNDANT_FIELDS:
         self.importCols = {k: v for k, v in self.cols.items() \
                       if not v.isRedundant()}
     else:
         self.importCols = self.cols
Ejemplo n.º 4
0
 def _resolveForeignKeys(self):
     """Links foreign keys to other tables. MUST be called AFTER all
     tables have been instantiated as TableInfo objects"""
     fkeycols = []
     self.fKeys = list()
     for fk in self._fKeysSA:
         self.fKeys.append(ForeignKeyInfo(fk, self))
         fkeycols.extend(fk["constrained_columns"])
     # Find all columns of the table that belong to some foreign key
     fkeycolsUniq = listUnique(fkeycols) if self._fKeysSA else list()
     self.fKeysCols = OrderedDict()
     for name in fkeycolsUniq:
         self.fKeysCols[name] = self.cols[name]
         self.cols[name].isFkCol = True
     # All tables this table refers to
     self.refTables = listUnique([k.refTable for k in self.fKeys])
     # Processes below can not be called earlier than that
     if self.isManyToMany():
         relType = "%s_%s" % (self.fKeys[0].refTable.labelName, self.fKeys[1].refTable.labelName)
         # relType attribute is set ONLY for such tables
         self.relType = _transformRelTypes(relType)
     if REMOVE_REDUNDANT_FIELDS:
         self.importCols = {k: v for k, v in self.cols.items() if not v.isRedundant()}
     else:
         self.importCols = self.cols