[storm] Mixing explicit and implicit joins

Shaun McCance shaunm at gnome.org
Mon Mar 16 16:39:17 GMT 2009


On Mon, 2009-03-16 at 14:24 +0900, James Henstridge wrote:
> 
> I was discussing something like this with Tim Penhey on IRC recently,
> 
> The implicit tables behaviour is implemented basically as follows:
> 
> 1. ResultSet object generates a Select() object that represents the
> query to perform.  It passes this to the connection to execute.
> 2. Connection runs compile() on the Select object to generate SQL.
> 3. The compile() function registered for Select objects compiles all
> the clauses (WHERE, GROUP BY, HAVING, ORDER BY).
> 4. Compiling some parts of the expression tree (Column and Table
> nodes) will add tables to the state.auto_tables list.
> 5. The referenced tables in state.auto_tables are used as the FROM
> clause, assuming that no tables have been set explicitly.
> 
> When you use store.using(), you are specifying the tables explicitly
> so in (5) the list of collected tables gets discarded.
> 
> When writing the SQLObject compatibility layer, we ended up needing
> something in between: specify some joins explicitly but still pick up
> any remaining tables via the auto_tables method listed above.  This
> sounds a lot like what you are after.
> 
> The solution used for the compatibility layer was a special
> AutoTables(expr, tables, replace=False) expression object.  The
> compilation function for this type adds the given tables (or joins) to
> state.auto_tables, which adds the joins to the query while not
> requiring you to explicitly list every table for the query.
> 
> So that will probably solve your problem.  The only question I'm not
> sure about is: do we consider AutoTables part of the public API we
> recommend people to use, or just an implementation detail of the
> SQLObject compatibility layer?
> 
> Given that there is demand for such a feature, I think we should
> expose something like this.  I am not sure AutoTables is the best API
> for this though.

Hey James,

Thanks for the response.  This sounds like exactly what I'm
looking for.  I did see AutoTables when looking through the
Storm source, but I couldn't quite figure out how to use it.
I think I don't really understand the compilation process.

I don't know what other people would find useful, but for me,
a simple utility function like get_tables_for_args would be
great.  It could just return a tuple of every referenced table.
I can take care of filtering out the ones I know I'm explicitly
joining.

For the time being, I've just required callers of my selection
function to pass a tuple of extra tables if they need them.
Not the most elegant solution, but it gets the job done and
lets me get on to other tasks.

--
Shaun





More information about the storm mailing list