| 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 |