示例#1
0
 def test_use_index(self):
     name_idx = index_name(Author, 'name')
     with CaptureLastQuery() as cap:
         list(Author.objects.filter(name__gt='').use_index(name_idx))
     assert ('USE INDEX (`' + name_idx + '`)') in cap.query
     used = used_indexes(cap.query)
     assert len(used) == 0 or name_idx in used
示例#2
0
 def test_force_index(self):
     name_idx = index_name(Author, 'name')
     with CaptureLastQuery() as cap:
         list(Author.objects.filter(name__gt='')
                            .force_index(name_idx))
     assert ('FORCE INDEX (`' + name_idx + '`)') in cap.query
     assert name_idx in used_indexes(cap.query)
 def test_force_index(self):
     name_idx = index_name(Author, 'name')
     with CaptureLastQuery() as cap:
         list(Author.objects.filter(name__gt='')
                            .force_index(name_idx))
     assert ('FORCE INDEX (`' + name_idx + '`)') in cap.query
     assert name_idx in used_indexes(cap.query)
示例#4
0
    def test_index_hint_force_order_by(self):
        name_idx = index_name(Author, 'name')
        with CaptureLastQuery() as cap:
            list(Author.objects.force_index(name_idx, for_='ORDER BY')
                               .order_by('name'))

        assert ('FORCE INDEX FOR ORDER BY (`' + name_idx + "`)") in cap.query
        assert name_idx in used_indexes(cap.query)
    def test_index_hint_force_order_by(self):
        name_idx = index_name(Author, 'name')
        with CaptureLastQuery() as cap:
            list(Author.objects.force_index(name_idx, for_='ORDER BY')
                               .order_by('name'))

        assert ('FORCE INDEX FOR ORDER BY (`' + name_idx + "`)") in cap.query
        assert name_idx in used_indexes(cap.query)
 def test_use_index(self):
     name_idx = index_name(Author, 'name')
     with CaptureLastQuery() as cap:
         list(Author.objects.filter(name__gt='')
                            .use_index(name_idx))
     assert ('USE INDEX (`' + name_idx + '`)') in cap.query
     used = used_indexes(cap.query)
     assert len(used) == 0 or name_idx in used
示例#7
0
 def test_ignore_index_multiple(self):
     name_idx = index_name(AuthorMultiIndex, 'name')
     name_country_idx = index_name(AuthorMultiIndex, 'name', 'country')
     with CaptureLastQuery() as cap:
         list(
             AuthorMultiIndex.objects.filter(name__gt='').ignore_index(
                 name_idx, name_country_idx))
     assert ('IGNORE INDEX (`' + name_idx + '`,`' + name_country_idx + '`)'
             in cap.query)
     used = used_indexes(cap.query)
     assert name_idx not in used
     assert name_country_idx not in used
 def test_ignore_index_multiple(self):
     name_idx = index_name(AuthorMultiIndex, 'name')
     name_country_idx = index_name(AuthorMultiIndex, 'name', 'country')
     with CaptureLastQuery() as cap:
         list(AuthorMultiIndex.objects
                              .filter(name__gt='')
                              .ignore_index(name_idx, name_country_idx))
     assert (
         'IGNORE INDEX (`' + name_idx + '`,`' + name_country_idx + '`)'
         in cap.query
     )
     used = used_indexes(cap.query)
     assert name_idx not in used
     assert name_country_idx not in used
示例#9
0
 def test_use_index_none(self):
     with CaptureLastQuery() as cap:
         list(Author.objects.values_list('name').distinct().use_index())
     assert 'USE INDEX () ' in cap.query
     assert used_indexes(cap.query) == set()
示例#10
0
 def test_ignore_index_primary(self):
     with CaptureLastQuery() as cap:
         list(Author.objects.filter(name__gt='').ignore_index('PRIMARY'))
     assert ('IGNORE INDEX (`PRIMARY`)') in cap.query
     assert 'PRIMARY' not in used_indexes(cap.query)
示例#11
0
 def test_force_index_primary(self):
     with CaptureLastQuery() as cap:
         list(Author.objects.force_index('PRIMARY'))
     assert ('FORCE INDEX (`PRIMARY`)') in cap.query
     used = used_indexes(cap.query)
     assert len(used) == 0 or 'PRIMARY' in used
示例#12
0
 def test_use_index_none(self):
     with CaptureLastQuery() as cap:
         list(Author.objects.values_list('name').distinct().use_index())
     assert 'USE INDEX () ' in cap.query
     assert used_indexes(cap.query) == set()
示例#13
0
 def test_ignore_index_primary(self):
     with CaptureLastQuery() as cap:
         list(Author.objects.filter(name__gt='').ignore_index('PRIMARY'))
     assert ('IGNORE INDEX (`PRIMARY`)') in cap.query
     assert 'PRIMARY' not in used_indexes(cap.query)
示例#14
0
 def test_force_index_primary(self):
     with CaptureLastQuery() as cap:
         list(Author.objects.force_index('PRIMARY'))
     assert ('FORCE INDEX (`PRIMARY`)') in cap.query
     used = used_indexes(cap.query)
     assert len(used) == 0 or 'PRIMARY' in used