Hi,
I am debugging performance issues using elixir at the moment and came
found a SELECT statement which
causes this. The following code will demonstrate it.
from elixir import *
metadata.bind = "sqlite://"
metadata.bind.echo = True
class Article(Entity):
name = Field(String(16))
tags = ManyToMany('Tag')
def __init__(self, name, tag=None):
self.name = name
if tag is not None:
tlist = tag.split(",")
for t in tlist:
t = t.strip()
tg = Tag.get_by(name=t)
if not tg:
tg = Tag(name=t)
self.tags.append(tg)
class Tag(Entity):
articles = ManyToMany('Article')
name = Field(String(16),required=True, index=True)
setup_all()
create_all()
t = Tag(name="t1")
session.commit()
a1 = Article(name='a1', tag="t2")
session.commit()
a2 = Article(name='a2', tag="t1")
session.commit()
In case the tag name already exists ("t1") elixir will generate the
the following SELECT statement which I don't understand why it is
there.
2010-08-30 13:12:01,051 INFO sqlalchemy.engine.base.Engine.0x...6350
SELECT __main___article.id AS __main___article_id,
__main___article.name AS __main___article_name
FROM __main___article, __main___tag_articles____main___article_tags
WHERE ? = __main___tag_articles____main___article_tags.__main___tag_id
AND __main___article.id =
__main___tag_articles____main___article_tags.__main___article_id
2010-08-30 13:12:01,051 INFO sqlalchemy.engine.base.Engine.0x...6350
(1,)
For a large number of rows this statement severely impacts the
performance.
Is this a bug or do I misunderstand something.
Cheers,
Malte.
--
You received this message because you are subscribed to the Google Groups
"SQLElixir" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlelixir?hl=en.