Ticket #11003: with-hints-13402.diff
File with-hints-13402.diff, 3.0 KB (added by , 14 years ago) |
---|
-
django/db/models/sql/compiler.py
441 441 continue 442 442 alias_str = (alias != name and ' %s' % alias or '') 443 443 if join_type and not first: 444 result.append('%s %s%s ON (%s.%s = %s.%s)'444 part ='%s %s%s ON (%s.%s = %s.%s)' \ 445 445 % (join_type, qn(name), alias_str, qn(lhs), 446 qn2(lhs_col), qn(alias), qn2(col)) )446 qn2(lhs_col), qn(alias), qn2(col)) 447 447 else: 448 448 connector = not first and ', ' or '' 449 result.append('%s%s%s' % (connector, qn(name), alias_str)) 449 part = '%s%s%s' % (connector, qn(name), alias_str) 450 for model, hint in self.query.hints.items(): 451 if model._meta.db_table == name: 452 part += ' USE INDEX (%s)' % ', '.join(hint) 453 result.append(part) 450 454 first = False 451 455 for t in self.query.extra_tables: 452 456 alias, unused = self.query.table_alias(t) -
django/db/models/sql/query.py
133 133 self.distinct = False 134 134 self.select_related = False 135 135 self.related_select_cols = [] 136 self.hints = {} 136 137 137 138 # SQL aggregate-related attributes 138 139 self.aggregates = SortedDict() # Maps alias -> SQL aggregate function … … 284 285 obj._extra_select_cache = self._extra_select_cache.copy() 285 286 obj.extra_tables = self.extra_tables 286 287 obj.extra_order_by = self.extra_order_by 288 obj.hints = self.hints 287 289 obj.deferred_loading = deepcopy(self.deferred_loading, memo=memo) 288 290 if self.filter_is_sticky and self.used_aliases: 289 291 obj.used_aliases = self.used_aliases.copy() … … 1641 1643 if order_by: 1642 1644 self.extra_order_by = order_by 1643 1645 1646 def add_hint(self, model, hint): 1647 add_to_dict(self.hints, model, hint) 1648 1644 1649 def clear_deferred_loading(self): 1645 1650 """ 1646 1651 Remove any fields from the deferred loading set. -
django/db/models/query.py
708 708 clone._db = alias 709 709 return clone 710 710 711 def with_hints(self, *args, **kwargs): 712 clone = self._clone() 713 for hint in args: 714 clone.query.add_hint(self.model, hint) 715 for model, hint in kwargs.items(): 716 clone.query.add_hint(model, hint) 717 return clone 718 711 719 ################################### 712 720 # PUBLIC INTROSPECTION ATTRIBUTES # 713 721 ###################################