From: Mike Bayer Date: Sun, 8 Mar 2015 19:32:21 +0000 (-0400) Subject: - random performance whacking vs. 0.9, in particular we have to watch X-Git-Tag: rel_1_0_0b1~37 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a421106c9d1d660af7c5d9aba5928dda20c950e1;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - random performance whacking vs. 0.9, in particular we have to watch for the slots-based __getattr__ thing getting hit --- diff --git a/examples/performance/__init__.py b/examples/performance/__init__.py index a4edfce363..5a1aeeb702 100644 --- a/examples/performance/__init__.py +++ b/examples/performance/__init__.py @@ -298,6 +298,7 @@ class Profiler(object): pr.disable() stats = pstats.Stats(pr).sort_stats('cumulative') + #stats.print_callers() self.stats.append(TestResult(self, fn, stats=stats)) return result diff --git a/examples/performance/large_resultsets.py b/examples/performance/large_resultsets.py index fbe77c759a..c13683040a 100644 --- a/examples/performance/large_resultsets.py +++ b/examples/performance/large_resultsets.py @@ -42,12 +42,13 @@ def setup_database(dburl, echo, num): s = Session(engine) for chunk in range(0, num, 10000): - s.bulk_insert_mappings(Customer, [ - { - 'name': 'customer name %d' % i, - 'description': 'customer description %d' % i - } for i in range(chunk, chunk + 10000) - ]) + s.execute( + Customer.__table__.insert(), + params=[ + { + 'name': 'customer name %d' % i, + 'description': 'customer description %d' % i + } for i in range(chunk, chunk + 10000)]) s.commit() diff --git a/examples/performance/short_selects.py b/examples/performance/short_selects.py index d81dc0dbbc..333fb96323 100644 --- a/examples/performance/short_selects.py +++ b/examples/performance/short_selects.py @@ -41,10 +41,10 @@ def setup_database(dburl, echo, num): sess.add_all([ Customer( id=i, name='c%d' % i, description="c%d" % i, - q="q%d" % i, - p="p%d" % i, - x="x%d" % i, - y="y%d" % i, + q=i * 10, + p=i * 20, + x=i * 30, + y=i * 40, ) for i in ids ]) diff --git a/lib/sqlalchemy/orm/base.py b/lib/sqlalchemy/orm/base.py index 875443e60d..c3f95fa109 100644 --- a/lib/sqlalchemy/orm/base.py +++ b/lib/sqlalchemy/orm/base.py @@ -327,7 +327,7 @@ def _is_mapped_class(entity): insp = inspection.inspect(entity, False) return insp is not None and \ - hasattr(insp, "mapper") and \ + not insp.is_clause_element and \ ( insp.is_mapper or insp.is_aliased_class diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index eac2da0836..fdee986d3c 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -3342,6 +3342,12 @@ class Bundle(object): """If True, queries for a single Bundle will be returned as a single entity, rather than an element within a keyed tuple.""" + is_clause_element = False + + is_mapper = False + + is_aliased_class = False + def __init__(self, name, *exprs, **kw): """Construct a new :class:`.Bundle`. diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py index 87029ec2bd..3384939b08 100644 --- a/lib/sqlalchemy/sql/selectable.py +++ b/lib/sqlalchemy/sql/selectable.py @@ -2484,21 +2484,20 @@ class Select(HasPrefixes, HasSuffixes, GenerativeSelect): seen = set() translate = self._from_cloned - def add(items): - for item in items: - if item is self: - raise exc.InvalidRequestError( - "select() construct refers to itself as a FROM") - if translate and item in translate: - item = translate[item] - if not seen.intersection(item._cloned_set): - froms.append(item) - seen.update(item._cloned_set) - - add(_from_objects(*self._raw_columns)) - if self._whereclause is not None: - add(_from_objects(self._whereclause)) - add(self._from_obj) + for item in itertools.chain( + _from_objects(*self._raw_columns), + _from_objects(self._whereclause) + if self._whereclause is not None else (), + self._from_obj + ): + if item is self: + raise exc.InvalidRequestError( + "select() construct refers to itself as a FROM") + if translate and item in translate: + item = translate[item] + if not seen.intersection(item._cloned_set): + froms.append(item) + seen.update(item._cloned_set) return froms