forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit04fe805
committed
Drop no-op CoerceToDomain nodes from expressions at planning time.
If a domain has no constraints, then CoerceToDomain doesn't really doanything and can be simplified to a RelabelType. This not onlyeliminates cycles at execution, but allows the planner to optimize better(for instance, match the coerced expression to an index on the underlyingcolumn). However, we do have to support invalidating the plan later ifa constraint gets added to the domain. That's comparable to the case ofa change to a SQL function that had been inlined into a plan, so all thenecessary logic already exists for plans depending on functions. Weneed only duplicate or share that logic for domains.ALTER DOMAIN ADD/DROP CONSTRAINT need to be taught to send out sinvalmessages for the domain's pg_type entry, since those operations don'tupdate that row. (ALTER DOMAIN SET/DROP NOT NULL do update that row,so no code change is needed for them.)Testing this revealed what's really a pre-existing bug in plpgsql:it caches the SQL-expression-tree expansion of type coercions andhad no provision for invalidating entries in that cache. Up to nowthat was only a problem if such an expression had inlined a SQLfunction that got changed, which is unlikely though not impossible.But failing to track changes of domain constraints breaks an existingregression test case and would likely cause practical problems too.We could fix that locally in plpgsql, but what seems like a betteridea is to build some generic infrastructure in plancache.c to storestandalone expressions and track invalidation events for them.(It's tempting to wonder whether plpgsql's "simple expression" stuffcould use this code with lower overhead than its current use of theheavyweight plancache APIs. But I've left that idea for later.)Other stuff fixed in passing:* Allow estimate_expression_value() to drop CoerceToDomainunconditionally, effectively assuming that the coercion will succeed.This will improve planner selectivity estimates for cases involvingestimatable expressions that are coerced to domains. We could havedone this independently of everything else here, but there wasn'tpreviously any need for eval_const_expressions_mutator to know aboutCoerceToDomain at all.* Use a dlist for plancache.c's list of cached plans, rather than amanually threaded singly-linked list. That eliminates a potentialperformance problem in DropCachedPlan.* Fix a couple of inconsistencies in typecmds.c about whetheroperations on domains drop RowExclusiveLock on pg_type. Our commonpractice is that DDL operations do drop catalog locks, so standardizeon that choice.Discussion:https://postgr.es/m/19958.1544122124@sss.pgh.pa.us1 parent52ac6cd commit04fe805
File tree
12 files changed
+510
-92
lines changed- src
- backend
- commands
- optimizer
- plan
- util
- utils/cache
- include
- optimizer
- utils
- pl/plpgsql/src
- test/regress
- expected
- sql
12 files changed
+510
-92
lines changedLines changed: 19 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
62 | 62 |
| |
63 | 63 |
| |
64 | 64 |
| |
| 65 | + | |
65 | 66 |
| |
66 | 67 |
| |
67 | 68 |
| |
| |||
2297 | 2298 |
| |
2298 | 2299 |
| |
2299 | 2300 |
| |
2300 |
| - | |
| 2301 | + | |
2301 | 2302 |
| |
2302 | 2303 |
| |
2303 | 2304 |
| |
| |||
2494 | 2495 |
| |
2495 | 2496 |
| |
2496 | 2497 |
| |
2497 |
| - | |
2498 |
| - | |
2499 | 2498 |
| |
2500 | 2499 |
| |
2501 | 2500 |
| |
| |||
2509 | 2508 |
| |
2510 | 2509 |
| |
2511 | 2510 |
| |
| 2511 | + | |
| 2512 | + | |
| 2513 | + | |
| 2514 | + | |
| 2515 | + | |
| 2516 | + | |
| 2517 | + | |
2512 | 2518 |
| |
2513 | 2519 |
| |
| 2520 | + | |
| 2521 | + | |
| 2522 | + | |
2514 | 2523 |
| |
2515 | 2524 |
| |
2516 | 2525 |
| |
| |||
2615 | 2624 |
| |
2616 | 2625 |
| |
2617 | 2626 |
| |
| 2627 | + | |
| 2628 | + | |
| 2629 | + | |
| 2630 | + | |
| 2631 | + | |
| 2632 | + | |
| 2633 | + | |
2618 | 2634 |
| |
2619 | 2635 |
| |
2620 | 2636 |
| |
|
Lines changed: 58 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
5923 | 5923 |
| |
5924 | 5924 |
| |
5925 | 5925 |
| |
| 5926 | + | |
| 5927 | + | |
| 5928 | + | |
| 5929 | + | |
| 5930 | + | |
5926 | 5931 |
| |
5927 | 5932 |
| |
5928 | 5933 |
| |
5929 |
| - | |
| 5934 | + | |
| 5935 | + | |
5930 | 5936 |
| |
5931 | 5937 |
| |
5932 | 5938 |
| |
| |||
5945 | 5951 |
| |
5946 | 5952 |
| |
5947 | 5953 |
| |
| 5954 | + | |
| 5955 | + | |
| 5956 | + | |
| 5957 | + | |
| 5958 | + | |
| 5959 | + | |
| 5960 | + | |
| 5961 | + | |
| 5962 | + | |
| 5963 | + | |
| 5964 | + | |
| 5965 | + | |
| 5966 | + | |
| 5967 | + | |
| 5968 | + | |
| 5969 | + | |
| 5970 | + | |
| 5971 | + | |
| 5972 | + | |
| 5973 | + | |
| 5974 | + | |
| 5975 | + | |
| 5976 | + | |
| 5977 | + | |
| 5978 | + | |
| 5979 | + | |
| 5980 | + | |
| 5981 | + | |
| 5982 | + | |
| 5983 | + | |
| 5984 | + | |
| 5985 | + | |
| 5986 | + | |
| 5987 | + | |
| 5988 | + | |
| 5989 | + | |
| 5990 | + | |
| 5991 | + | |
| 5992 | + | |
| 5993 | + | |
| 5994 | + | |
| 5995 | + | |
| 5996 | + | |
| 5997 | + | |
| 5998 | + | |
| 5999 | + | |
| 6000 | + | |
| 6001 | + | |
| 6002 | + | |
| 6003 | + | |
| 6004 | + | |
5948 | 6005 |
| |
5949 | 6006 |
| |
5950 | 6007 |
| |
|
Lines changed: 57 additions & 7 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
138 | 138 |
| |
139 | 139 |
| |
140 | 140 |
| |
141 |
| - | |
142 |
| - | |
| 141 | + | |
143 | 142 |
| |
144 | 143 |
| |
145 | 144 |
| |
| |||
175 | 174 |
| |
176 | 175 |
| |
177 | 176 |
| |
178 |
| - | |
179 |
| - | |
| 177 | + | |
| 178 | + | |
180 | 179 |
| |
181 | 180 |
| |
182 | 181 |
| |
| |||
2577 | 2576 |
| |
2578 | 2577 |
| |
2579 | 2578 |
| |
| 2579 | + | |
| 2580 | + | |
| 2581 | + | |
| 2582 | + | |
| 2583 | + | |
| 2584 | + | |
| 2585 | + | |
| 2586 | + | |
| 2587 | + | |
| 2588 | + | |
| 2589 | + | |
| 2590 | + | |
| 2591 | + | |
| 2592 | + | |
| 2593 | + | |
| 2594 | + | |
| 2595 | + | |
| 2596 | + | |
| 2597 | + | |
| 2598 | + | |
| 2599 | + | |
| 2600 | + | |
| 2601 | + | |
| 2602 | + | |
| 2603 | + | |
| 2604 | + | |
| 2605 | + | |
| 2606 | + | |
| 2607 | + | |
| 2608 | + | |
| 2609 | + | |
| 2610 | + | |
| 2611 | + | |
| 2612 | + | |
| 2613 | + | |
| 2614 | + | |
2580 | 2615 |
| |
2581 | 2616 |
| |
2582 | 2617 |
| |
| |||
2586 | 2621 |
| |
2587 | 2622 |
| |
2588 | 2623 |
| |
| 2624 | + | |
| 2625 | + | |
| 2626 | + | |
| 2627 | + | |
| 2628 | + | |
| 2629 | + | |
| 2630 | + | |
2589 | 2631 |
| |
2590 | 2632 |
| |
2591 | 2633 |
| |
| |||
2615 | 2657 |
| |
2616 | 2658 |
| |
2617 | 2659 |
| |
2618 |
| - | |
| 2660 | + | |
| 2661 | + | |
| 2662 | + | |
| 2663 | + | |
| 2664 | + | |
| 2665 | + | |
| 2666 | + | |
| 2667 | + | |
| 2668 | + | |
2619 | 2669 |
| |
2620 | 2670 |
| |
2621 | 2671 |
| |
2622 | 2672 |
| |
2623 | 2673 |
| |
2624 |
| - | |
2625 |
| - | |
2626 | 2674 |
| |
2627 | 2675 |
| |
2628 | 2676 |
| |
| |||
2662 | 2710 |
| |
2663 | 2711 |
| |
2664 | 2712 |
| |
| 2713 | + | |
| 2714 | + | |
2665 | 2715 |
| |
2666 | 2716 |
| |
2667 | 2717 |
|
Lines changed: 65 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3699 | 3699 |
| |
3700 | 3700 |
| |
3701 | 3701 |
| |
| 3702 | + | |
| 3703 | + | |
| 3704 | + | |
| 3705 | + | |
| 3706 | + | |
| 3707 | + | |
| 3708 | + | |
| 3709 | + | |
| 3710 | + | |
| 3711 | + | |
| 3712 | + | |
| 3713 | + | |
| 3714 | + | |
| 3715 | + | |
| 3716 | + | |
| 3717 | + | |
| 3718 | + | |
| 3719 | + | |
| 3720 | + | |
| 3721 | + | |
| 3722 | + | |
| 3723 | + | |
| 3724 | + | |
| 3725 | + | |
| 3726 | + | |
| 3727 | + | |
| 3728 | + | |
| 3729 | + | |
| 3730 | + | |
| 3731 | + | |
| 3732 | + | |
| 3733 | + | |
| 3734 | + | |
| 3735 | + | |
| 3736 | + | |
| 3737 | + | |
| 3738 | + | |
| 3739 | + | |
| 3740 | + | |
| 3741 | + | |
| 3742 | + | |
| 3743 | + | |
| 3744 | + | |
| 3745 | + | |
| 3746 | + | |
| 3747 | + | |
| 3748 | + | |
| 3749 | + | |
| 3750 | + | |
| 3751 | + | |
| 3752 | + | |
| 3753 | + | |
| 3754 | + | |
| 3755 | + | |
| 3756 | + | |
| 3757 | + | |
| 3758 | + | |
| 3759 | + | |
| 3760 | + | |
| 3761 | + | |
| 3762 | + | |
| 3763 | + | |
| 3764 | + | |
| 3765 | + | |
3702 | 3766 |
| |
3703 | 3767 |
| |
3704 | 3768 |
| |
| |||
3770 | 3834 |
| |
3771 | 3835 |
| |
3772 | 3836 |
| |
3773 |
| - | |
| 3837 | + | |
3774 | 3838 |
| |
3775 | 3839 |
| |
3776 | 3840 |
| |
|
0 commit comments
Comments
(0)