forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit0dcf753
committed
Improve the numeric width_bucket() computation.
Formerly, the computation of the bucket index involved callingdiv_var() with a scale determined by select_div_scale(), and thentaking the floor of the result. That involved computing anything from16 to 1000 digits after the decimal point, only for floor_var() tothrow them away. In addition, the quotient was computed with roundingin the final digit, which meant that in rare cases the whole resultcould round up to the wrong bucket, and could exceed count. Thus itwas also necessary to clamp the result to the range [1, count], thoughthat didn't prevent the result being in the wrong internal bucket.Instead, compute the quotient using floor division, which guaranteesthe correct result, as specified by the SQL spec, and doesn't need tobe clamped. This is both much simpler and more efficient, since it nolonger computes any quotient digits after the decimal point.In addition, it is not necessary to have separate code to handlereversed bounds, since the signs cancel out when dividing.As withb0e9e4d anda2a0c7c, no back-patch.Dean Rasheed, reviewed by Joel Jacobson.Discussion:https://postgr.es/m/CAEZATCVbJH%2BLE9EXW8Rk3AxLe%3DjbOk2yrT_AUJGGh5Rah6zoeg%40mail.gmail.com1 parent628c1d1 commit0dcf753
1 file changed
+18
-31
lines changedLines changed: 18 additions & 31 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
608 | 608 |
| |
609 | 609 |
| |
610 | 610 |
| |
611 |
| - | |
| 611 | + | |
612 | 612 |
| |
613 | 613 |
| |
614 | 614 |
| |
| |||
1896 | 1896 |
| |
1897 | 1897 |
| |
1898 | 1898 |
| |
1899 |
| - | |
| 1899 | + | |
1900 | 1900 |
| |
1901 | 1901 |
| |
1902 | 1902 |
| |
| |||
1907 | 1907 |
| |
1908 | 1908 |
| |
1909 | 1909 |
| |
1910 |
| - | |
| 1910 | + | |
1911 | 1911 |
| |
1912 | 1912 |
| |
1913 | 1913 |
| |
| |||
1926 | 1926 |
| |
1927 | 1927 |
| |
1928 | 1928 |
| |
1929 |
| - | |
| 1929 | + | |
1930 | 1930 |
| |
1931 | 1931 |
| |
1932 | 1932 |
| |
1933 | 1933 |
| |
1934 | 1934 |
| |
1935 |
| - | |
1936 |
| - | |
| 1935 | + | |
1937 | 1936 |
| |
1938 | 1937 |
| |
1939 | 1938 |
| |
| |||
1943 | 1942 |
| |
1944 | 1943 |
| |
1945 | 1944 |
| |
1946 |
| - | |
1947 |
| - | |
1948 |
| - | |
1949 |
| - | |
1950 |
| - | |
1951 |
| - | |
1952 |
| - | |
1953 |
| - | |
1954 |
| - | |
1955 |
| - | |
| 1945 | + | |
| 1946 | + | |
| 1947 | + | |
| 1948 | + | |
| 1949 | + | |
| 1950 | + | |
| 1951 | + | |
| 1952 | + | |
| 1953 | + | |
| 1954 | + | |
| 1955 | + | |
1956 | 1956 |
| |
1957 | 1957 |
| |
1958 | 1958 |
| |
1959 |
| - | |
1960 |
| - | |
1961 |
| - | |
1962 |
| - | |
1963 |
| - | |
1964 |
| - | |
1965 |
| - | |
1966 |
| - | |
1967 |
| - | |
1968 |
| - | |
1969 |
| - | |
1970 |
| - | |
1971 |
| - | |
1972 |
| - | |
1973 |
| - | |
| 1959 | + | |
| 1960 | + | |
1974 | 1961 |
| |
1975 | 1962 |
| |
1976 | 1963 |
| |
|
0 commit comments
Comments
(0)