Loading django/db/models/sql/compiler.py +10 −0 Original line number Diff line number Diff line Loading @@ -750,6 +750,16 @@ class SQLCompiler(object): yield row def has_results(self): """ Backends (e.g. NoSQL) can override this in order to use optimized versions of "query has any results." """ # This is always executed on a query clone, so we can modify self.query self.query.add_extra({'a': 1}, None, None, None, None, None) self.query.set_extra_mask(['a']) return bool(self.execute_sql(SINGLE)) def execute_sql(self, result_type=MULTI): """ Run the query against the database and returns the result(s). The Loading django/db/models/sql/query.py +1 −3 Original line number Diff line number Diff line Loading @@ -401,12 +401,10 @@ class Query(object): def has_results(self, using): q = self.clone() q.clear_select_clause() q.add_extra({'a': 1}, None, None, None, None, None) q.set_extra_mask(['a']) q.clear_ordering(True) q.set_limits(high=1) compiler = q.get_compiler(using=using) return bool(compiler.execute_sql(SINGLE)) return compiler.has_results() def combine(self, rhs, connector): """ Loading Loading
django/db/models/sql/compiler.py +10 −0 Original line number Diff line number Diff line Loading @@ -750,6 +750,16 @@ class SQLCompiler(object): yield row def has_results(self): """ Backends (e.g. NoSQL) can override this in order to use optimized versions of "query has any results." """ # This is always executed on a query clone, so we can modify self.query self.query.add_extra({'a': 1}, None, None, None, None, None) self.query.set_extra_mask(['a']) return bool(self.execute_sql(SINGLE)) def execute_sql(self, result_type=MULTI): """ Run the query against the database and returns the result(s). The Loading
django/db/models/sql/query.py +1 −3 Original line number Diff line number Diff line Loading @@ -401,12 +401,10 @@ class Query(object): def has_results(self, using): q = self.clone() q.clear_select_clause() q.add_extra({'a': 1}, None, None, None, None, None) q.set_extra_mask(['a']) q.clear_ordering(True) q.set_limits(high=1) compiler = q.get_compiler(using=using) return bool(compiler.execute_sql(SINGLE)) return compiler.has_results() def combine(self, rhs, connector): """ Loading