powa-team / powa-web

PoWA user interface
http://powa.readthedocs.io/
73 stars 30 forks source link

Number of executions can be incorrect in query detail view #15

Closed champeric closed 8 years ago

champeric commented 8 years ago

PoWA Web 3.0.2

If the same query is executed in multiple databases, the query detail view will report the wrong # of executions (and runtime). For example, if 4 databases have the same query, the # of executions will be 4 times the real value.

From what I can see, this is because in query.py's class QueryDetail, there's a join with powa_statements but the join is only on queryid. Since queryid is the same for the same query in all databases, it will return a row for each database (dbid) and those will be grouped and summed giving wrong results.

Changing the code to also join on dbid seems to correct the problem. The fix I did is champeric/powa-web@c490b3130b, but I'm not familiar with SQLAlchemy nor PoWA's code in general so I don't know what else it could affect.

Thanks

rjuju commented 8 years ago

Hello,

The queryid should be different between databases since the queryid is computed from objects oid, which are different on every databases. The only exception is system tables which have the same oid on every databases. Was the query on system objects?

Anyway, that's clearly a bug and your patch looks good to me, well done :) Do you want to send a pull request?

champeric commented 8 years ago

Thanks for the feedback.

You are completely right, it was a query on system objects and the tests I did afterwards were with dumb queries like SELECT 1 WHERE now() = now();. I didn't realize that for more normal queries it wouldn't cause problems. I just started playing with PoWA on a test database and I didn't have real queries to analyze yet.

I'll send the pull request.