我最近正在用 Django 建立一个化合物数据库。我在处理模型遍历时遇到了麻烦。以下是我的问题:
楷模:
class CompoundStructures(models.Model):
molregno = models.CharField(max_length=27L, primary_key=True)
molfile = models.TextField(blank=True)
standard_inchi = models.TextField(blank=True)
standard_inchi_key = models.CharField(max_length=27L, unique=True)
canonical_smiles = models.TextField(blank=True)
molformula = models.CharField(max_length=100L, blank=True)
class Meta:
db_table = 'compound_structures'
def __unicode__(self):
return self.molformula
该模型的数据库中有 1,000,000 多条记录:我运行如下代码:
all_mols = CompoundStructures.objects.all()
mol_0 = all_mols[0] //quick
mol_100 = all_mols[100] //normal
mol_10000 = all_mols[10000] //slow
mol_100000 = all_mols[100000] //really slow!
为什么随着索引号变大它变得越来越慢?这使我无法遍历CompoundStructures
.