apache / apache/shardingsphere
PostgreSQL Proxy behavior different with PostgreSQL when doing math
- Dominant language
- Java
- Stars
- 20.8k
- Forks
- 6.9k
- Avg merge
- 11h 35m
- Merged PRs (30d)
- 326
Description
## Bug Report
### Which version of ShardingSphere did you use?
master - 935a8108a6e411cab79c7861fe1d7315d27f941c
### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
ShardingSphere-Proxy PostgreSQL
### Expected behavior
```
psql -h 127.0.0.1 -p 5432 -Upostgres -c 'select 12.3 ^ (-45.6)'
?column?
---------------------------------------------------------------------
0.00000000000000000000000000000000000000000000000001996764828785491
(1 row)
```
```
psql -h 127.0.0.1 -p 5432 -Upostgres -c 'select n, 10.0 ^ n as "10^n", (10.0 ^ n) * (10.0 ^ (-n)) = 1 as ok from generate_series(-20, 20) n;'
n | 10^n | ok
-----+----------------------------------------+----
-20 | 0.0000000000000000 | f
-19 | 0.0000000000000000 | f
-18 | 0.0000000000000000 | f
-17 | 0.0000000000000000 | f
-16 | 0.0000000000000001 | t
-15 | 0.0000000000000010 | t
-14 | 0.0000000000000100 | t
-13 | 0.0000000000001000 | t
-12 | 0.0000000000010000 | t
-11 | 0.0000000000100000 | t
-10 | 0.0000000001000000 | t
-9 | 0.0000000010000000 | t
-8 | 0.0000000100000000 | t
-7 | 0.0000001000000000 | t
-6 | 0.0000010000000000 | t
-5 | 0.0000100000000000 | t
-4 | 0.0001000000000000 | t
-3 | 0.0010000000000000 | t
-2 | 0.0100000000000000 | t
-1 | 0.1000000000000000 | t
0 | 1.0000000000000000 | t
1 | 10.0000000000000000 | t
2 | 100.0000000000000000 | t
3 | 1000.0000000000000000 | t
4 | 10000.0000000000000000 | t
5 | 100000.0000000000000000 | t
6 | 1000000.0000000000000000 | t
7 | 10000000.0000000000000000 | t
8 | 100000000.0000000000000000 | t
9 | 1000000000.0000000000000000 | t
10 | 10000000000.0000000000000000 | t
11 | 100000000000.0000000000000000 | t
12 | 1000000000000.0000000000000000 | t
13 | 10000000000000.0000000000000000 | t
14 | 100000000000000.0000000000000000 | t
15 | 1000000000000000.0000000000000000 | t
16 | 10000000000000000.0000000000000000 | t
17 | 100000000000000000.0000000000000000 | f
18 | 1000000000000000000.0000000000000000 | f
19 | 10000000000000000000.0000000000000000 | f
20 | 100000000000000000000.0000000000000000 | f
(41 rows)
```
### Actual behavior
```
psql -h 127.0.0.1 -p 55432 -Upostgres -c 'select 12.3 ^ (-45.6)'
Password for user postgres:
?column?
-----------------------
1.996764828785491E-50
(1 row)
```
```
psql -h 127.0.0.1 -p 55432 -Upostgres -c 'select n, 10.0 ^ n as "10^n", (10.0 ^ n) * (10.0 ^ (-n)) = 1 as ok from generate_series(-20, 20) n;'
Password for user postgres:
n | 10^n | ok
-----+----------------------------------------+-------
-20 | 0E-16 | false
-19 | 0E-16 | false
-18 | 0E-16 | false
-17 | 0E-16 | false
-16 | 1E-16 | true
-15 | 1.0E-15 | true
-14 | 1.00E-14 | true
-13 | 1.000E-13 | true
-12 | 1.0000E-12 | true
-11 | 1.00000E-11 | true
-10 | 1.000000E-10 | true
-9 | 1.0000000E-9 | true
-8 | 1.00000000E-8 | true
-7 | 1.000000000E-7 | true
-6 | 0.0000010000000000 | true
-5 | 0.0000100000000000 | true
-4 | 0.0001000000000000 | true
-3 | 0.0010000000000000 | true
-2 | 0.0100000000000000 | true
-1 | 0.1000000000000000 | true
0 | 1.0000000000000000 | true
1 | 10.0000000000000000 | true
2 | 100.0000000000000000 | true
3 | 1000.0000000000000000 | true
4 | 10000.0000000000000000 | true
5 | 100000.0000000000000000 | true
6 | 1000000.0000000000000000 | true
7 | 10000000.0000000000000000 | true
8 | 100000000.0000000000000000 | true
9 | 1000000000.0000000000000000 | true
10 | 10000000000.0000000000000000 | true
11 | 100000000000.0000000000000000 | true
12 | 1000000000000.0000000000000000 | true
13 | 10000000000000.0000000000000000 | true
14 | 100000000000000.0000000000000000 | true
15 | 1000000000000000.0000000000000000 | true
16 | 10000000000000000.0000000000000000 | true
17 | 100000000000000000.0000000000000000 | false
18 | 1000000000000000000.0000000000000000 | false
19 | 10000000000000000000.0000000000000000 | false
20 | 100000000000000000000.0000000000000000 | false
```
### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
No rules configured.
```sql
select 12.3 ^ (-45.6)
select n, 10.0 ^ n as "10^n", (10.0 ^ n) * (10.0 ^ (-n)) = 1 as ok from generate_series(-20, 20) n
```
### Reason analyze (If you can)
PostgreSQL

ShardingSphere-Proxy PostgreSQL

Contributor guide
Research direction
Start with the ShardingSphere-Proxy PostgreSQL path and the two SQL expressions shown in the reproduction steps; compare its numeric results and formatting with PostgreSQL on the same queries. Done means the proxy matches PostgreSQL for the exponentiation results and displayed values, including the negative fractional exponent case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, postgresql
- Domain
- database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100