forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commita1b4f28
committed
Consider BufFiles when adjusting hashjoin parameters
Until now ExecChooseHashTableSize() considered only the size of thein-memory hash table, and ignored the memory needed for the batch files.Which can be a significant amount, because each batch needs two BufFiles(each with a BLCKSZ buffer). The same issue applies to increasing thenumber of batches during execution.It's also possible to trigger a "batch explosion", e.g. due to duplicatevalues or skew. We've seen reports of joins with hundreds of thousands(or even millions) of batches, consuming gigabytes of memory, triggeringOOM errors. These cases may be fairly rare, but it's clearly possible tohit them.These issues can't be prevented during planning. Even if we improvethat, it does not help with execution-time batch explosion. We canhowever reduce the impact and use as little memory as possible.This patch improves the behavior by adjusting how the memory is dividedbetween the hash table and batch files. It may be better to use fewerbatch files, even if it means the hash table will exceed the limit.The capacity of the hash node may be increased either by doubling henumber of batches, or doubling the size of the in-memory hash table. Theoutcome is the same, but the memory usage may be very different. For lownbatch values it's better to add batches, for high nbatch values it'sbetter to allow a larger hash table.The patch considers both options, both during the initial sizing andthen during execution, to minimize how much the limit gets exceeded.It might seem this patch is relaxing the memory limit - allowing it tobe exceeded. But that's not really the case. It has always been likethat, except the memory used by batches was ignored.Allowing the hash table to grow may also prevent the batch explosion.If there's a large batch that can't be split (due to hash collisions orduplicate values), at some point the memory limit will increase enoughfor the batch to fit into the hash table.This patch was in the works for a long time. The early versions wereposted in 2019, and revived every year or two when we happened to getthe next report of OOM due to a hashjoin batch explosion. Each of thosepatch versions were reviewed by a couple people. I'm mentioning onlyMelanie Plageman and Robert Haas, because they reviewed the lastversion, and the older patches are very different.Reviewed-by: Melanie Plageman, Robert HaasDiscussion:https://postgr.es/m/7bed6c08-72a0-4ab9-a79c-e01fcdd0940f@vondra.meDiscussion:https://postgr.es/m/20190504003414.bulcbnge3rhwhcsh%40developmentDiscussion:https://postgr.es/m/20190428141901.5dsbge2ka3rxmpk6%40development1 parent8b886a4 commita1b4f28
1 file changed
+129
-0
lines changedLines changed: 129 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
848 | 848 |
| |
849 | 849 |
| |
850 | 850 |
| |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
851 | 935 |
| |
852 | 936 |
| |
853 | 937 |
| |
| |||
890 | 974 |
| |
891 | 975 |
| |
892 | 976 |
| |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
893 | 1018 |
| |
894 | 1019 |
| |
895 | 1020 |
| |
| |||
913 | 1038 |
| |
914 | 1039 |
| |
915 | 1040 |
| |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
916 | 1045 |
| |
917 | 1046 |
| |
918 | 1047 |
| |
|
0 commit comments
Comments
(0)