- Notifications
You must be signed in to change notification settings - Fork28
Commitab1f0c8
committed
Change representation of statement lists, and add statement location info.
This patch makes several changes that improve the consistency ofrepresentation of lists of statements. It's always been the casethat the output of parse analysis is a list of Query nodes, whateverthe types of the individual statements in the list. This patch bringssimilar consistency to the outputs of raw parsing and planning steps:* The output of raw parsing is now always a list of RawStmt nodes;the statement-type-dependent nodes are one level down from that.* The output of pg_plan_queries() is now always a list of PlannedStmtnodes, even for utility statements. In the case of a utility statement,"planning" just consists of wrapping a CMD_UTILITY PlannedStmt aroundthe utility node. This list representation is now used in Portal andCachedPlan plan lists, replacing the former convention of intermixingPlannedStmts with bare utility-statement nodes.Now, every list of statements has a consistent head-node type dependingon how far along it is in processing. This allows changing many placesthat formerly used generic "Node *" pointers to use a more specificpointer type, thus reducing the number of IsA() tests and casts needed,as well as improving code clarity.Also, the post-parse-analysis representation of DECLARE CURSOR is changedso that it looks more like EXPLAIN, PREPARE, etc. That is, the containedSELECT remains a child of the DeclareCursorStmt rather than getting flippedaround to be the other way. It's now true for both Query and PlannedStmtthat utilityStmt is non-null if and only if commandType is CMD_UTILITY.That allows simplifying a lot of places that were testing both fields.(I think some of those were just defensive programming, but in many places,it was actually necessary to avoid confusing DECLARE CURSOR with SELECT.)Because PlannedStmt carries a canSetTag field, we're also able to get ridof some ad-hoc rules about how to reconstruct canSetTag for a bare utilitystatement; specifically, the assumption that a utility is canSetTag if andonly if it's the only one in its list. While I see no near-term need forrelaxing that restriction, it's nice to get rid of the ad-hocery.The API of ProcessUtility() is changed so that what it's passed is thewrapper PlannedStmt not just the bare utility statement. This will affectall users of ProcessUtility_hook, but the changes are pretty trivial; seethe affected contrib modules for examples of the minimum change needed.(Most compilers should give pointer-type-mismatch warnings for uncorrectedcode.)There's also a change in the API of ExplainOneQuery_hook, to pass throughcursorOptions instead of expecting hook functions to know what to pick.This is needed because of the DECLARE CURSOR changes, but really shouldhave been done in 9.6; it's unlikely that any extant hook functionsknow about using CURSOR_OPT_PARALLEL_OK.Finally, teach gram.y to save statement boundary locations in RawStmtnodes, and pass those through to Query and PlannedStmt nodes. This allowsmore intelligent handling of cases where a source query string containsmultiple statements. This patch doesn't actually do anything with theinformation, but a follow-on patch will. (Passing this information throughcleanly is the true motivation for these changes; while I think this is allgood cleanup, it's unlikely we'd have bothered without this end goal.)catversion bump because addition of location fields to struct Queryaffects stored rules.This patch is by me, but it owes a good deal to Fabien Coelho who dida lot of preliminary work on the problem, and also reviewed the patch.Discussion:https://postgr.es/m/alpine.DEB.2.20.1612200926310.29821@lancre1 parent75abb95 commitab1f0c8
File tree
53 files changed
+788
-547
lines changed- contrib
- pg_stat_statements
- sepgsql
- src
- backend
- catalog
- commands
- executor
- nodes
- optimizer
- plan
- prep
- util
- parser
- rewrite
- tcop
- utils
- cache
- mmgr
- include
- catalog
- commands
- executor
- nodes
- parser
- tcop
- utils
- pl/plpgsql/src
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
53 files changed
+788
-547
lines changedLines changed: 8 additions & 6 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
292 | 292 |
| |
293 | 293 |
| |
294 | 294 |
| |
295 |
| - | |
| 295 | + | |
296 | 296 |
| |
297 | 297 |
| |
298 | 298 |
| |
| |||
942 | 942 |
| |
943 | 943 |
| |
944 | 944 |
| |
945 |
| - | |
| 945 | + | |
946 | 946 |
| |
947 | 947 |
| |
948 | 948 |
| |
| 949 | + | |
| 950 | + | |
949 | 951 |
| |
950 | 952 |
| |
951 | 953 |
| |
| |||
979 | 981 |
| |
980 | 982 |
| |
981 | 983 |
| |
982 |
| - | |
| 984 | + | |
983 | 985 |
| |
984 | 986 |
| |
985 | 987 |
| |
986 |
| - | |
| 988 | + | |
987 | 989 |
| |
988 | 990 |
| |
989 | 991 |
| |
| |||
1044 | 1046 |
| |
1045 | 1047 |
| |
1046 | 1048 |
| |
1047 |
| - | |
| 1049 | + | |
1048 | 1050 |
| |
1049 | 1051 |
| |
1050 | 1052 |
| |
1051 |
| - | |
| 1053 | + | |
1052 | 1054 |
| |
1053 | 1055 |
| |
1054 | 1056 |
| |
|
Lines changed: 4 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
297 | 297 |
| |
298 | 298 |
| |
299 | 299 |
| |
300 |
| - | |
| 300 | + | |
301 | 301 |
| |
302 | 302 |
| |
303 | 303 |
| |
304 | 304 |
| |
305 | 305 |
| |
306 | 306 |
| |
| 307 | + | |
307 | 308 |
| |
308 | 309 |
| |
309 | 310 |
| |
| |||
362 | 363 |
| |
363 | 364 |
| |
364 | 365 |
| |
365 |
| - | |
| 366 | + | |
366 | 367 |
| |
367 | 368 |
| |
368 | 369 |
| |
369 |
| - | |
| 370 | + | |
370 | 371 |
| |
371 | 372 |
| |
372 | 373 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
934 | 934 |
| |
935 | 935 |
| |
936 | 936 |
| |
937 |
| - | |
| 937 | + | |
938 | 938 |
| |
939 | 939 |
| |
940 | 940 |
| |
|
Lines changed: 23 additions & 16 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
287 | 287 |
| |
288 | 288 |
| |
289 | 289 |
| |
290 |
| - | |
291 |
| - | |
| 290 | + | |
| 291 | + | |
292 | 292 |
| |
293 | 293 |
| |
294 | 294 |
| |
295 |
| - | |
296 |
| - | |
| 295 | + | |
| 296 | + | |
297 | 297 |
| |
298 | 298 |
| |
299 | 299 |
| |
| |||
770 | 770 |
| |
771 | 771 |
| |
772 | 772 |
| |
773 |
| - | |
774 |
| - | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
775 | 777 |
| |
776 | 778 |
| |
777 | 779 |
| |
778 | 780 |
| |
779 | 781 |
| |
780 | 782 |
| |
781 |
| - | |
| 783 | + | |
782 | 784 |
| |
783 | 785 |
| |
784 | 786 |
| |
| |||
929 | 931 |
| |
930 | 932 |
| |
931 | 933 |
| |
932 |
| - | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
933 | 938 |
| |
934 | 939 |
| |
935 | 940 |
| |
| |||
945 | 950 |
| |
946 | 951 |
| |
947 | 952 |
| |
948 |
| - | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
949 | 958 |
| |
950 | 959 |
| |
951 | 960 |
| |
| |||
981 | 990 |
| |
982 | 991 |
| |
983 | 992 |
| |
984 |
| - | |
985 |
| - | |
986 | 993 |
| |
987 | 994 |
| |
988 | 995 |
| |
| |||
1364 | 1371 |
| |
1365 | 1372 |
| |
1366 | 1373 |
| |
1367 |
| - | |
1368 |
| - | |
| 1374 | + | |
| 1375 | + | |
1369 | 1376 |
| |
1370 | 1377 |
| |
1371 | 1378 |
| |
| |||
1456 | 1463 |
| |
1457 | 1464 |
| |
1458 | 1465 |
| |
1459 |
| - | |
| 1466 | + | |
1460 | 1467 |
| |
1461 | 1468 |
| |
1462 | 1469 |
| |
| |||
1747 | 1754 |
| |
1748 | 1755 |
| |
1749 | 1756 |
| |
1750 |
| - | |
1751 |
| - | |
| 1757 | + | |
| 1758 | + | |
1752 | 1759 |
| |
1753 | 1760 |
| |
1754 | 1761 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
326 | 326 |
| |
327 | 327 |
| |
328 | 328 |
| |
329 |
| - | |
| 329 | + | |
330 | 330 |
| |
331 | 331 |
| |
332 | 332 |
| |
|
Lines changed: 35 additions & 11 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
53 | 53 |
| |
54 | 54 |
| |
55 | 55 |
| |
56 |
| - | |
| 56 | + | |
| 57 | + | |
57 | 58 |
| |
58 | 59 |
| |
59 | 60 |
| |
| |||
245 | 246 |
| |
246 | 247 |
| |
247 | 248 |
| |
248 |
| - | |
| 249 | + | |
| 250 | + | |
249 | 251 |
| |
250 | 252 |
| |
251 | 253 |
| |
| |||
329 | 331 |
| |
330 | 332 |
| |
331 | 333 |
| |
332 |
| - | |
| 334 | + | |
| 335 | + | |
333 | 336 |
| |
334 | 337 |
| |
335 | 338 |
| |
| |||
341 | 344 |
| |
342 | 345 |
| |
343 | 346 |
| |
344 |
| - | |
| 347 | + | |
| 348 | + | |
345 | 349 |
| |
346 | 350 |
| |
347 | 351 |
| |
| |||
351 | 355 |
| |
352 | 356 |
| |
353 | 357 |
| |
354 |
| - | |
| 358 | + | |
355 | 359 |
| |
356 | 360 |
| |
357 | 361 |
| |
| |||
385 | 389 |
| |
386 | 390 |
| |
387 | 391 |
| |
| 392 | + | |
| 393 | + | |
388 | 394 |
| |
389 | 395 |
| |
390 | 396 |
| |
391 | 397 |
| |
392 | 398 |
| |
393 | 399 |
| |
394 | 400 |
| |
395 |
| - | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
396 | 423 |
| |
397 | 424 |
| |
398 | 425 |
| |
| |||
423 | 450 |
| |
424 | 451 |
| |
425 | 452 |
| |
426 |
| - | |
427 |
| - | |
428 |
| - | |
429 |
| - | |
430 |
| - | |
431 | 453 |
| |
432 | 454 |
| |
433 | 455 |
| |
| |||
444 | 466 |
| |
445 | 467 |
| |
446 | 468 |
| |
| 469 | + | |
| 470 | + | |
447 | 471 |
| |
448 | 472 |
| |
449 | 473 |
| |
|
Lines changed: 11 additions & 11 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
712 | 712 |
| |
713 | 713 |
| |
714 | 714 |
| |
715 |
| - | |
| 715 | + | |
716 | 716 |
| |
717 | 717 |
| |
718 | 718 |
| |
| |||
724 | 724 |
| |
725 | 725 |
| |
726 | 726 |
| |
727 |
| - | |
728 |
| - | |
729 |
| - | |
730 |
| - | |
731 |
| - | |
732 |
| - | |
| 727 | + | |
733 | 728 |
| |
734 | 729 |
| |
735 | 730 |
| |
736 | 731 |
| |
737 | 732 |
| |
738 |
| - | |
739 |
| - | |
| 733 | + | |
740 | 734 |
| |
741 | 735 |
| |
742 | 736 |
| |
743 |
| - | |
| 737 | + | |
744 | 738 |
| |
745 | 739 |
| |
746 | 740 |
| |
| |||
754 | 748 |
| |
755 | 749 |
| |
756 | 750 |
| |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
757 | 756 |
| |
758 | 757 |
| |
759 | 758 |
| |
| |||
1434 | 1433 |
| |
1435 | 1434 |
| |
1436 | 1435 |
| |
1437 |
| - | |
| 1436 | + | |
| 1437 | + | |
1438 | 1438 |
| |
1439 | 1439 |
| |
1440 | 1440 |
| |
|
Lines changed: 12 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1572 | 1572 |
| |
1573 | 1573 |
| |
1574 | 1574 |
| |
1575 |
| - | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
1576 | 1578 |
| |
1577 | 1579 |
| |
1578 | 1580 |
| |
| |||
1593 | 1595 |
| |
1594 | 1596 |
| |
1595 | 1597 |
| |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + | |
1596 | 1606 |
| |
1597 |
| - | |
| 1607 | + | |
1598 | 1608 |
| |
1599 | 1609 |
| |
1600 | 1610 |
| |
|
0 commit comments
Comments
(0)