-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sql: internal error: DECIMAL: could not evaluate #40327
Comments
I've been looking into this. The problem seems to be coming from constant.go
It calls the following function, which can only deal with a precision of 2000 places, but the above string has 2019 trailing zeroes.
Next I'll try to figure out why the number ends up getting represented like that. |
I found that any decimal division with a divisor of
In this case, the constant folding uses eval.go, which uses the context But later (as mentioned in the above comment), @mjibson I believe you have the most knowledge about how we should be using decimals and the various contexts. Do you know why Also, as an aside, I am curious why we have implemented |
The various decimal contexts were chosen by me to try to match the postgres behavior of the corresponding operation, but stuff dealing with precision and exponents near the edge has not been fully tested or made identical. We could probably change folding to use HighPrecisionCtx? Although I don't think that would affect this bug at all. I'm not exactly clear on why or when SetString is getting called? Is it at the end of constant folding when converting to a typed datum? We have a few options:
No, it should be used only in the same places where it's used in normal execution. It's used in decimal - decimal subtraction: cockroach/pkg/sql/sem/tree/eval.go Line 744 in f81ac2b
This is to match the gda spec for divide. See the tests at https://github.com/cockroachdb/apd/blob/master/testdata/divide.decTest#L601. That is, none of here made this decision, we just followed the spec. Most decimal implementations around follow that spec (java, python, etc.). |
Thanks for the very helpful background and suggestions! I have a slightly better picture of what's going on. First off, here is a simple repro:
As it turns out, any one of the following things ends up solving the error.
If we do options 1 or 2, then the SQL query in the original bug report produces a result that has 2019 decimal places. If we do option 3, then the result has no decimal places. Based on your comment, it seems like maybe option 1 is the best approach and is desirable for other reasons. And maybe it would be safe to do 3 as well for good measure, though I am not sure if this would violate the spec that you referenced. I'm guessing you already knew this, but it seems like as far as Postgres goes, it does not support |
Allow decimals of any length, like how Postgres does. This also prevents errors from happening in some cases like division by infinity. relates to cockroachdb#40327 Release note: None
39685: workload/tpcc: extend --wait to also support fractions r=danhhz,petermattis a=knz In order to use TPC-C for operational testing (i.e. NOT benchmarking) it is useful to increase the rate of transactions without altogether saturating the TPS capacity (`--wait=false`). For this purpose, this commit extends the syntax accepted by `--wait` to recognize a multiplier which is applied to all wait times. The default is 1.0 (i.e. 100% of the wait time required by a benchmark). The words `true`/`on` and `false`/`off` are aliases for 1.0 and 0.0, respectively 40380: exec: use same decimal context as non-vec r=rafiss a=rafiss Use the same decimal contexts that eval.go uses for decimal arithmetic. based on discussion in #40327 Release note: None Co-authored-by: Raphael 'kena' Poss <[email protected]> Co-authored-by: Rafi Shamim <[email protected]>
The text was updated successfully, but these errors were encountered: