Fixed #19351 -- SQLite bulk_insert of more than 500 single-field objs
This commit is contained in:
parent
a27582484c
commit
0a0a0d66b3
|
@ -120,8 +120,12 @@ class DatabaseOperations(BaseDatabaseOperations):
|
||||||
"""
|
"""
|
||||||
SQLite has a compile-time default (SQLITE_LIMIT_VARIABLE_NUMBER) of
|
SQLite has a compile-time default (SQLITE_LIMIT_VARIABLE_NUMBER) of
|
||||||
999 variables per query.
|
999 variables per query.
|
||||||
|
|
||||||
|
If there is just single field to insert, then we can hit another
|
||||||
|
limit, SQLITE_MAX_COMPOUND_SELECT which defaults to 500.
|
||||||
"""
|
"""
|
||||||
return (999 // len(fields)) if len(fields) > 0 else len(objs)
|
limit = 999 if len(fields) > 1 else 500
|
||||||
|
return (limit // len(fields)) if len(fields) > 0 else len(objs)
|
||||||
|
|
||||||
def date_extract_sql(self, lookup_type, field_name):
|
def date_extract_sql(self, lookup_type, field_name):
|
||||||
# sqlite doesn't support extract, so we fake it with the user-defined
|
# sqlite doesn't support extract, so we fake it with the user-defined
|
||||||
|
|
|
@ -102,6 +102,14 @@ class BulkCreateTests(TestCase):
|
||||||
101)
|
101)
|
||||||
self.assertEqual(TwoFields.objects.filter(f2__gte=901).count(), 101)
|
self.assertEqual(TwoFields.objects.filter(f2__gte=901).count(), 101)
|
||||||
|
|
||||||
|
@skipUnlessDBFeature('has_bulk_insert')
|
||||||
|
def test_large_single_field_batch(self):
|
||||||
|
# SQLite had a problem with more than 500 UNIONed selects in single
|
||||||
|
# query.
|
||||||
|
Restaurant.objects.bulk_create([
|
||||||
|
Restaurant() for i in range(0, 501)
|
||||||
|
])
|
||||||
|
|
||||||
@skipUnlessDBFeature('has_bulk_insert')
|
@skipUnlessDBFeature('has_bulk_insert')
|
||||||
def test_large_batch_efficiency(self):
|
def test_large_batch_efficiency(self):
|
||||||
with override_settings(DEBUG=True):
|
with override_settings(DEBUG=True):
|
||||||
|
|
Loading…
Reference in New Issue