Berkeley DB XML index timing script
17 January 2008
22:39
as Python
See http://www.cmlenz.net/archives/2005/08/berkeley-db-xml-indices for the context
| 1 | from datetime import datetime |
|---|---|
| 2 | import dbxml |
| 3 | |
| 4 | indices = [ |
| 5 | ('', 'build', 'node-metadata-equality-decimal'), |
| 6 | ('', 'step', 'node-metadata-equality-string'), |
| 7 | ('', 'type', 'node-attribute-equality-string') |
| 8 | ] |
| 9 | |
| 10 | queries = [ |
| 11 | '/report[dbxml:metadata("build")=1 and dbxml:metadata("step")="test"]', |
| 12 | '/report[dbxml:metadata("build")=1 and dbxml:metadata("step")="test" and @type="unittest"]' |
| 13 | ] |
| 14 | |
| 15 | def time_queries(): |
| 16 | ctxt = mgr.createQueryContext() |
| 17 | for query in queries: |
| 18 | started = datetime.now() |
| 19 | print 'Executing query:', query |
| 20 | results = mgr.query('collection("bitten.dbxml")' + query, ctxt) |
| 21 | stopped = datetime.now() |
| 22 | print '%d results, took %s' % (results.size(), stopped - started) |
| 23 | |
| 24 | def print_indices(): |
| 25 | print 'Indices:' |
| 26 | ispec = container.getIndexSpecification() |
| 27 | for index in ispec: |
| 28 | print ' {%s}:%s "%s"' % (index.get_uri(), index.get_name(), index.get_index()) |
| 29 | |
| 30 | mgr = dbxml.XmlManager() |
| 31 | container = mgr.openContainer('bitten.dbxml') |
| 32 | uc = mgr.createUpdateContext() |
| 33 | print_indices() |
| 34 | |
| 35 | time_queries() |
| 36 | |
| 37 | |
| 38 | for uri, name, index in indices: |
| 39 | container.addIndex(uri, name, index, uc) |
| 40 | print_indices() |
| 41 | |
| 42 | time_queries() |
| 43 | |
| 44 | for uri, name, index in indices: |
| 45 | container.deleteIndex(uri, name, index, uc) |
Comments
No comments so far.
