diff -r 55950a87e230 django/db/models/query.py
--- a/django/db/models/query.py	Sat Apr 03 11:45:31 2010 +0000
+++ b/django/db/models/query.py	Mon Apr 05 00:24:32 2010 +0800
@@ -3,6 +3,7 @@
 """
 
 from copy import deepcopy
+from itertools import izip
 
 from django.db import connections, router, transaction, IntegrityError
 from django.db.models.aggregates import Aggregate
@@ -429,11 +430,13 @@
         # becoming too long.
         seen_objs = None
         while 1:
-            # Collect all the objects to be deleted in this chunk, and all the
+            # Collect a chunk of objects to be deleted, and then all the
             # objects that are related to the objects that are to be deleted.
+            # The chunking *isn't* done by slicing the del_query because we
+            # need to maintain the query cache on del_query (see #12328)
             seen_objs = CollectedObjects(seen_objs)
-            for object in del_query[:CHUNK_SIZE]:
-                object._collect_sub_objects(seen_objs)
+            for i,obj in izip(range(CHUNK_SIZE), del_query):
+                obj._collect_sub_objects(seen_objs)
 
             if not seen_objs:
                 break
diff -r 55950a87e230 django/db/models/sql/compiler.py
--- a/django/db/models/sql/compiler.py	Sat Apr 03 11:45:31 2010 +0000
+++ b/django/db/models/sql/compiler.py	Mon Apr 05 00:24:32 2010 +0800
@@ -120,13 +120,15 @@
         """
         Perform the same functionality as the as_sql() method, returning an
         SQL string and parameters. However, the alias prefixes are bumped
-        beforehand (in a copy -- the current query isn't changed) and any
-        ordering is removed.
+        beforehand (in a copy -- the current query isn't changed), and any
+        ordering is removed if the query is unsliced.
 
         Used when nesting this query inside another.
         """
         obj = self.query.clone()
-        obj.clear_ordering(True)
+        if obj.low_mark == 0 and obj.high_mark is None:
+            # If there is no slicing in use, then we can safely drop all ordering
+            obj.clear_ordering(True)
         obj.bump_prefix()
         return obj.get_compiler(connection=self.connection).as_sql()
 
diff -r 55950a87e230 tests/regressiontests/queries/models.py
--- a/tests/regressiontests/queries/models.py	Sat Apr 03 11:45:31 2010 +0000
+++ b/tests/regressiontests/queries/models.py	Mon Apr 05 00:24:32 2010 +0800
@@ -19,7 +19,8 @@
     from django.utils.itercompat import sorted
 
 class DumbCategory(models.Model):
-    pass
+    def __unicode__(self):
+        return unicode(self.id)
 
 class NamedCategory(DumbCategory):
     name = models.CharField(max_length=10)
diff -r 55950a87e230 tests/regressiontests/queries/tests.py
--- a/tests/regressiontests/queries/tests.py	Sat Apr 03 11:45:31 2010 +0000
+++ b/tests/regressiontests/queries/tests.py	Mon Apr 05 00:24:32 2010 +0800
@@ -1,27 +1,51 @@
 import unittest
-from models import Tag, Annotation
+
 from django.db.models import Count
+from django.test import TestCase
+
+from models import Tag, Annotation, DumbCategory
 
 class QuerysetOrderedTests(unittest.TestCase):
     """
     Tests for the Queryset.ordered attribute.
     """
-    
+
     def test_no_default_or_explicit_ordering(self):
         self.assertEqual(Annotation.objects.all().ordered, False)
 
     def test_cleared_default_ordering(self):
         self.assertEqual(Tag.objects.all().ordered, True)
         self.assertEqual(Tag.objects.all().order_by().ordered, False)
-        
+
     def test_explicit_ordering(self):
         self.assertEqual(Annotation.objects.all().order_by('id').ordered, True)
-        
+
     def test_order_by_extra(self):
         self.assertEqual(Annotation.objects.all().extra(order_by=['id']).ordered, True)
-        
+
     def test_annotated_ordering(self):
         qs = Annotation.objects.annotate(num_notes=Count('notes'))
         self.assertEqual(qs.ordered, False)
         self.assertEqual(qs.order_by('num_notes').ordered, True)
-        
\ No newline at end of file
+
+
+class SubqueryTests(TestCase):
+    def setUp(self):
+        DumbCategory.objects.create(id=1)
+        DumbCategory.objects.create(id=2)
+        DumbCategory.objects.create(id=3)
+
+    def test_ordered_subselect(self):
+        "Subselects can't have a manually specified ordering"
+        query = DumbCategory.objects.filter(id__in=DumbCategory.objects.order_by('-id')[0:2]).order_by('id')
+        self.assertEquals(repr(query), "[<DumbCategory: 2>, <DumbCategory: 3>]")
+
+        query = DumbCategory.objects.filter(id__in=DumbCategory.objects.order_by('-id')[:2]).order_by('id')
+        self.assertEquals(repr(query), "[<DumbCategory: 2>, <DumbCategory: 3>]")
+
+        query = DumbCategory.objects.filter(id__in=DumbCategory.objects.order_by('-id')[2:]).order_by('id')
+        self.assertEquals(repr(query), "[<DumbCategory: 1>]")
+
+    def test_sliced_delete(self):
+        DumbCategory.objects.filter(id__in=DumbCategory.objects.order_by('-id')[0:1]).delete()
+        self.assertEquals(repr(DumbCategory.objects.order_by('id')), "[<DumbCategory: 1>, <DumbCategory: 2>]")
