MCPcopy Index your code
hub / github.com/MagicStack/asyncpg / test_prepare_14_explain

Method test_prepare_14_explain

tests/test_prepare.py:254–282  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

252 self.assertEqual([r[0] for r in rows], [0, 1, 2, 3])
253
254 async def test_prepare_14_explain(self):
255 # Test simple EXPLAIN.
256 stmt = await self.con.prepare('SELECT typname FROM pg_type')
257 plan = await stmt.explain()
258 self.assertEqual(plan[0]['Plan']['Relation Name'], 'pg_type')
259
260 # Test "EXPLAIN ANALYZE".
261 stmt = await self.con.prepare(
262 'SELECT typname, typlen FROM pg_type WHERE typlen > $1')
263 plan = await stmt.explain(2, analyze=True)
264 self.assertEqual(plan[0]['Plan']['Relation Name'], 'pg_type')
265 self.assertIn('Actual Total Time', plan[0]['Plan'])
266
267 # Test that 'EXPLAIN ANALYZE' is executed in a transaction
268 # that gets rollbacked.
269 tr = self.con.transaction()
270 await tr.start()
271 try:
272 await self.con.execute('CREATE TABLE mytab (a int)')
273 stmt = await self.con.prepare(
274 'INSERT INTO mytab (a) VALUES (1), (2)')
275 plan = await stmt.explain(analyze=True)
276 self.assertEqual(plan[0]['Plan']['Operation'], 'Insert')
277
278 # Check that no data was inserted
279 res = await self.con.fetch('SELECT * FROM mytab')
280 self.assertEqual(res, [])
281 finally:
282 await tr.rollback()
283
284 async def test_prepare_15_stmt_gc_cache_disabled(self):
285 # Test that even if the statements cache is off, we're still

Callers

nothing calls this directly

Calls 7

prepareMethod · 0.80
explainMethod · 0.80
transactionMethod · 0.80
rollbackMethod · 0.80
startMethod · 0.45
executeMethod · 0.45
fetchMethod · 0.45

Tested by

no test coverage detected