Re:Myth: Select * is Bad
by andrewflnr on Sunday August 25, 2013 @04:16PM
(#6273518)
I'm sure someone has tried, but has anyone done a good job on an ORM that actually lets you select which columns to load and only selects those?
[ Parent
| on HN ]
Don't most ORM allow that?
i.e. rails' ActiveRecord allows you to select columns easily in most cases:
User.where(..) # all fields
User.where(..).select(:name, :id) # only two of them
joe.boards.select(:title) # only one in join
joe.boards.pluck(:title) # only column value instead of full objects with one attribute set
Though I recall it's involved for #belongs_to relations.You should also be able to setup the select as a default per-class, other than per query.
I suspect, I likely didn't understand your question, could you expand it?
Re:Myth: Select * is Bad
by andrewflnr on Sunday August 25, 2013 @04:52PM
(#6273675)
It's possible I'm just ignorant of the capabilities of most ORMs. My only real experience is with the Django ORM. AFAIK, if you select an object, it wants to make sure all the members of the object are populated.
My apologies if it was a dumb question. :)
Django has it too. https://docs.djangoproject.com/en/dev/ref/models/querysets/#...
By default yes, but like most ORMs you can ask to populate only some members: https://docs.djangoproject.com/en/dev/ref/models/querysets/#...
Django offer a couple of options:
.only(… field list…)
.defer(… fields to fetch on demand…)
https://docs.djangoproject.com/en/dev/ref/models/querysets/#...here you go:
http://use-the-index-luke.com/sql/join/hash-join-partial-obj...
It's really a PIA.
Recently, I've learned about http://jooq.org/ — not having checked in detail yet, it might be easier there.
SQL alchemy - it does everything the right way.
Re:Myth: Select * is Bad
by barrydahlberg on Sunday August 25, 2013 @04:52PM
(#6273676)
.NETs Entity Framework lets you do this using the fantastic LINQ syntax. Commonly you will say which objects to select, then give a projection into a new anonymous type with only the columns you want.