Commits

Vadim Statishin  committed 67d7712

Add index for searching fields

  • Participants
  • Parent commits a206c4a

Comments (0)

Files changed (5)

File geoobjects/migrations/0001_initial.py

+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        # Adding model 'GeobazaRanges'
+        db.create_table(u'geoobjects_geobazaranges', (
+            (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('start', self.gf('django.db.models.fields.CharField')(max_length=15)),
+            ('end', self.gf('django.db.models.fields.CharField')(max_length=15)),
+            ('ip_int', self.gf('django.db.models.fields.BigIntegerField')()),
+            ('length', self.gf('django.db.models.fields.BigIntegerField')()),
+            ('tld', self.gf('django.db.models.fields.CharField')(max_length=4, null=True)),
+            ('obj_id', self.gf('django.db.models.fields.PositiveIntegerField')(max_length=11)),
+        ))
+        db.send_create_signal(u'geoobjects', ['GeobazaRanges'])
+
+        # Adding unique constraint on 'GeobazaRanges', fields ['ip_int', 'length']
+        db.create_unique(u'geoobjects_geobazaranges', ['ip_int', 'length'])
+
+        # Adding model 'GeobazaObjects'
+        db.create_table(u'geoobjects_geobazaobjects', (
+            (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('parent_id', self.gf('django.db.models.fields.PositiveIntegerField')()),
+            ('type', self.gf('django.db.models.fields.CharField')(max_length=100)),
+            ('name_en', self.gf('django.db.models.fields.CharField')(max_length=255)),
+            ('name_ru', self.gf('django.db.models.fields.CharField')(default=None, max_length=255, null=True)),
+            ('lat', self.gf('django.db.models.fields.FloatField')(default=None, null=True)),
+            ('lon', self.gf('django.db.models.fields.FloatField')(default=None, null=True)),
+        ))
+        db.send_create_signal(u'geoobjects', ['GeobazaObjects'])
+
+
+    def backwards(self, orm):
+        # Removing unique constraint on 'GeobazaRanges', fields ['ip_int', 'length']
+        db.delete_unique(u'geoobjects_geobazaranges', ['ip_int', 'length'])
+
+        # Deleting model 'GeobazaRanges'
+        db.delete_table(u'geoobjects_geobazaranges')
+
+        # Deleting model 'GeobazaObjects'
+        db.delete_table(u'geoobjects_geobazaobjects')
+
+
+    models = {
+        u'geoobjects.geobazaobjects': {
+            'Meta': {'object_name': 'GeobazaObjects'},
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'lat': ('django.db.models.fields.FloatField', [], {'default': 'None', 'null': 'True'}),
+            'lon': ('django.db.models.fields.FloatField', [], {'default': 'None', 'null': 'True'}),
+            'name_en': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+            'name_ru': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '255', 'null': 'True'}),
+            'parent_id': ('django.db.models.fields.PositiveIntegerField', [], {}),
+            'type': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+        },
+        u'geoobjects.geobazaranges': {
+            'Meta': {'unique_together': "(('ip_int', 'length'),)", 'object_name': 'GeobazaRanges'},
+            'end': ('django.db.models.fields.CharField', [], {'max_length': '15'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'ip_int': ('django.db.models.fields.BigIntegerField', [], {}),
+            'length': ('django.db.models.fields.BigIntegerField', [], {}),
+            'obj_id': ('django.db.models.fields.PositiveIntegerField', [], {'max_length': '11'}),
+            'start': ('django.db.models.fields.CharField', [], {'max_length': '15'}),
+            'tld': ('django.db.models.fields.CharField', [], {'max_length': '4', 'null': 'True'})
+        }
+    }
+
+    complete_apps = ['geoobjects']

File geoobjects/migrations/0002_auto.py

+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        # Adding index on 'GeobazaObjects', fields ['name_ru']
+        db.create_index(u'geoobjects_geobazaobjects', ['name_ru'])
+
+        # Adding index on 'GeobazaObjects', fields ['name_en']
+        db.create_index(u'geoobjects_geobazaobjects', ['name_en'])
+
+        # Adding index on 'GeobazaObjects', fields ['type']
+        db.create_index(u'geoobjects_geobazaobjects', ['type'])
+
+        # Adding index on 'GeobazaRanges', fields ['ip_int']
+        db.create_index(u'geoobjects_geobazaranges', ['ip_int'])
+
+        # Adding index on 'GeobazaRanges', fields ['length']
+        db.create_index(u'geoobjects_geobazaranges', ['length'])
+
+
+    def backwards(self, orm):
+        # Removing index on 'GeobazaRanges', fields ['length']
+        db.delete_index(u'geoobjects_geobazaranges', ['length'])
+
+        # Removing index on 'GeobazaRanges', fields ['ip_int']
+        db.delete_index(u'geoobjects_geobazaranges', ['ip_int'])
+
+        # Removing index on 'GeobazaObjects', fields ['type']
+        db.delete_index(u'geoobjects_geobazaobjects', ['type'])
+
+        # Removing index on 'GeobazaObjects', fields ['name_en']
+        db.delete_index(u'geoobjects_geobazaobjects', ['name_en'])
+
+        # Removing index on 'GeobazaObjects', fields ['name_ru']
+        db.delete_index(u'geoobjects_geobazaobjects', ['name_ru'])
+
+
+    models = {
+        u'geoobjects.geobazaobjects': {
+            'Meta': {'object_name': 'GeobazaObjects'},
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'lat': ('django.db.models.fields.FloatField', [], {'default': 'None', 'null': 'True'}),
+            'lon': ('django.db.models.fields.FloatField', [], {'default': 'None', 'null': 'True'}),
+            'name_en': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
+            'name_ru': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '255', 'null': 'True', 'db_index': 'True'}),
+            'parent_id': ('django.db.models.fields.PositiveIntegerField', [], {}),
+            'type': ('django.db.models.fields.CharField', [], {'max_length': '100', 'db_index': 'True'})
+        },
+        u'geoobjects.geobazaranges': {
+            'Meta': {'unique_together': "(('ip_int', 'length'),)", 'object_name': 'GeobazaRanges'},
+            'end': ('django.db.models.fields.CharField', [], {'max_length': '15'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'ip_int': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True'}),
+            'length': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True'}),
+            'obj_id': ('django.db.models.fields.PositiveIntegerField', [], {'max_length': '11'}),
+            'start': ('django.db.models.fields.CharField', [], {'max_length': '15'}),
+            'tld': ('django.db.models.fields.CharField', [], {'max_length': '4', 'null': 'True'})
+        }
+    }
+
+    complete_apps = ['geoobjects']

File geoobjects/migrations/__init__.py

Empty file added.

File geoobjects/models.py

 class GeobazaRanges(models.Model):
     start = models.CharField(max_length=15)
     end = models.CharField(max_length=15)
-    ip_int = models.BigIntegerField()
-    length = models.BigIntegerField()
+    ip_int = models.BigIntegerField(db_index=True)
+    length = models.BigIntegerField(db_index=True)
     tld = models.CharField(max_length=4, null=True)
     obj_id = models.PositiveIntegerField(max_length=11)
 
 
 class GeobazaObjects(models.Model):
     parent_id = models.PositiveIntegerField()
-    type = models.CharField(max_length=100)
-    name_en = models.CharField(max_length=255)
-    name_ru = models.CharField(max_length=255, null=True, default=None)
+    type = models.CharField(max_length=100, db_index=True)
+    name_en = models.CharField(max_length=255, db_index=True)
+    name_ru = models.CharField(max_length=255, null=True, default=None, db_index=True)
     lat = models.FloatField(null=True, default=None)
     lon = models.FloatField(null=True, default=None)
 
 
 setup(
     name='geoobjects',
-    version='0.2.5.14',
+    version='0.2.5.15',
     packages=['geoobjects', 'geoobjects.management', 'geoobjects.management.commands'],
     scripts=['scripts/geoobjects_import_mysql.sh'],
     install_requires=['django'],