1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

Modify the float4 datatype to be pass-by-val. Along the way, remove the last

uses of the long-deprecated float32 in contrib/seg; the definitions themselves
are still there, but no longer used.  fmgr/README updated to match.

I added a CREATE FUNCTION to account for existing seg_center() code in seg.c
too, and some tests for it and the neighbor functions.  At the same time,
remove checks for NULL which are not needed (because the functions are declared
STRICT).

I had to do some adjustments to contrib's btree_gist too.  The choices for
representation there are not ideal for changing the underlying types :-(

Original patch by Zoltan Boszormenyi, with some adjustments by me.
This commit is contained in:
Alvaro Herrera
2008-04-18 18:43:09 +00:00
parent b8e5581d76
commit 7861d72ea2
20 changed files with 392 additions and 129 deletions

View File

@ -2575,3 +2575,4 @@
23.7
24
24.0
\N

View File

@ -1065,3 +1065,154 @@ SELECT * FROM test_seg WHERE s @> '11..11.3' GROUP BY s;
10.7 .. 12.3
(143 rows)
-- Test functions
SELECT seg_lower(s), seg_center(s), seg_upper(s)
FROM test_seg WHERE s @> '11.2..11.3' OR s IS NULL ORDER BY s;
seg_lower | seg_center | seg_upper
-----------+------------+-----------
-Infinity | -Infinity | 40
-Infinity | -Infinity | 82
-Infinity | -Infinity | 90
1 | 7 | 13
1.3 | 6.65 | 12
2 | 6.75 | 11.5
2.1 | 6.95 | 11.8
2.3 | Infinity | Infinity
2.3 | Infinity | Infinity
2.4 | 6.85 | 11.3
2.5 | 7 | 11.5
2.5 | 7.15 | 11.8
2.6 | Infinity | Infinity
2.7 | 7.35 | 12
3 | Infinity | Infinity
3 | 30.5 | 58
3.1 | 7.3 | 11.5
3.5 | 7.5 | 11.5
3.5 | 7.85 | 12.2
4 | 8 | 12
4 | Infinity | Infinity
4 | 8 | 12
4 | 7.85 | 11.7
4 | 8.25 | 12.5
4 | 8.5 | 13
4 | 32 | 60
4 | Infinity | Infinity
4.2 | 7.85 | 11.5
4.2 | 7.95 | 11.7
4.5 | 8.25 | 12
4.5 | 8 | 11.5
4.5 | 8.25 | 12
4.5 | 8.25 | 12
4.5 | 8.5 | 12.5
4.5 | 59.75 | 115
4.7 | 8.25 | 11.8
4.8 | 8.15 | 11.5
4.8 | 8.2 | 11.6
4.8 | 8.65 | 12.5
4.8 | Infinity | Infinity
4.9 | 8.45 | 12
4.9 | Infinity | Infinity
5 | 8.25 | 11.5
5 | 8.5 | 12
5 | 17.5 | 30
5 | 8.2 | 11.4
5 | 8.25 | 11.5
5 | 8.3 | 11.6
5 | 8.35 | 11.7
5 | 8.5 | 12
5 | 8.5 | 12
5 | 8.5 | 12
5.2 | 8.35 | 11.5
5.2 | 8.6 | 12
5.25 | 8.625 | 12
5.3 | 8.4 | 11.5
5.3 | 9.15 | 13
5.3 | 47.65 | 90
5.3 | Infinity | Infinity
5.4 | Infinity | Infinity
5.5 | 8.5 | 11.5
5.5 | 8.6 | 11.7
5.5 | 8.75 | 12
5.5 | 8.75 | 12
5.5 | 9 | 12.5
5.5 | 9.5 | 13.5
5.5 | Infinity | Infinity
5.5 | Infinity | Infinity
5.7 | Infinity | Infinity
5.9 | Infinity | Infinity
6 | 8.75 | 11.5
6 | 9 | 12
6 | 8.75 | 11.5
6 | 9.5 | 13
6 | 8.75 | 11.5
6.1 | 9.05 | 12
6.1 | Infinity | Infinity
6.2 | 8.85 | 11.5
6.3 | Infinity | Infinity
6.5 | 9 | 11.5
6.5 | 9.25 | 12
6.5 | 9.25 | 12
6.5 | Infinity | Infinity
6.6 | Infinity | Infinity
6.7 | 9.1 | 11.5
6.7 | Infinity | Infinity
6.75 | Infinity | Infinity
6.8 | Infinity | Infinity
6.9 | 9.55 | 12.2
6.9 | 48.45 | 90
6.9 | Infinity | Infinity
7 | 9.25 | 11.5
7 | 9.25 | 11.5
7 | 9.25 | 11.5
7 | Infinity | Infinity
7.15 | Infinity | Infinity
7.2 | 10.35 | 13.5
7.3 | 48.65 | 90
7.3 | Infinity | Infinity
7.3 | Infinity | Infinity
7.4 | 9.75 | 12.1
7.4 | Infinity | Infinity
7.5 | 9.5 | 11.5
7.5 | 9.75 | 12
7.5 | Infinity | Infinity
7.7 | 9.6 | 11.5
7.7 | Infinity | Infinity
7.75 | Infinity | Infinity
8 | 9.85 | 11.7
8 | 10 | 12
8 | 10.5 | 13
8.2 | Infinity | Infinity
8.3 | Infinity | Infinity
8.5 | 10 | 11.5
8.5 | 10.5 | 12.5
8.5 | Infinity | Infinity
8.6 | 53.8 | 99
8.7 | 10 | 11.3
8.7 | 10.2 | 11.7
8.9 | 10.2 | 11.5
9 | 10.5 | 12
9 | 10.15 | 11.3
9 | 10.25 | 11.5
9 | 10.5 | 12
9 | Infinity | Infinity
9.2 | 10.6 | 12
9.4 | 10.8 | 12.2
9.5 | 10.75 | 12
9.5 | 10.85 | 12.2
9.5 | Infinity | Infinity
9.6 | 10.55 | 11.5
9.7 | 10.6 | 11.5
9.7 | 10.85 | 12
9.8 | 11.15 | 12.5
10 | 10.8 | 11.6
10 | 10.75 | 11.5
10 | 11.25 | 12.5
10 | 11.25 | 12.5
10.2 | 11 | 11.8
10.5 | 11 | 11.5
10.5 | 11 | 11.5
10.5 | 12 | 13.5
10.7 | 11.5 | 12.3
| |
(144 rows)

View File

@ -1065,3 +1065,154 @@ SELECT * FROM test_seg WHERE s @> '11..11.3' GROUP BY s;
10.7 .. 12.3
(143 rows)
-- Test functions
SELECT seg_lower(s), seg_center(s), seg_upper(s)
FROM test_seg WHERE s @> '11.2..11.3' OR s IS NULL ORDER BY s;
seg_lower | seg_center | seg_upper
-----------+------------+-----------
-Infinity | -Infinity | 40
-Infinity | -Infinity | 82
-Infinity | -Infinity | 90
1 | 7 | 13
1.3 | 6.65 | 12
2 | 6.75 | 11.5
2.1 | 6.95 | 11.8
2.3 | Infinity | Infinity
2.3 | Infinity | Infinity
2.4 | 6.85 | 11.3
2.5 | 7 | 11.5
2.5 | 7.15 | 11.8
2.6 | Infinity | Infinity
2.7 | 7.35 | 12
3 | Infinity | Infinity
3 | 30.5 | 58
3.1 | 7.3 | 11.5
3.5 | 7.5 | 11.5
3.5 | 7.85 | 12.2
4 | 8 | 12
4 | Infinity | Infinity
4 | 8 | 12
4 | 7.85 | 11.7
4 | 8.25 | 12.5
4 | 8.5 | 13
4 | 32 | 60
4 | Infinity | Infinity
4.2 | 7.85 | 11.5
4.2 | 7.95 | 11.7
4.5 | 8.25 | 12
4.5 | 8 | 11.5
4.5 | 8.25 | 12
4.5 | 8.25 | 12
4.5 | 8.5 | 12.5
4.5 | 59.75 | 115
4.7 | 8.25 | 11.8
4.8 | 8.15 | 11.5
4.8 | 8.2 | 11.6
4.8 | 8.65 | 12.5
4.8 | Infinity | Infinity
4.9 | 8.45 | 12
4.9 | Infinity | Infinity
5 | 8.25 | 11.5
5 | 8.5 | 12
5 | 17.5 | 30
5 | 8.2 | 11.4
5 | 8.25 | 11.5
5 | 8.3 | 11.6
5 | 8.35 | 11.7
5 | 8.5 | 12
5 | 8.5 | 12
5 | 8.5 | 12
5.2 | 8.35 | 11.5
5.2 | 8.6 | 12
5.25 | 8.625 | 12
5.3 | 8.4 | 11.5
5.3 | 9.15 | 13
5.3 | 47.65 | 90
5.3 | Infinity | Infinity
5.4 | Infinity | Infinity
5.5 | 8.5 | 11.5
5.5 | 8.6 | 11.7
5.5 | 8.75 | 12
5.5 | 8.75 | 12
5.5 | 9 | 12.5
5.5 | 9.5 | 13.5
5.5 | Infinity | Infinity
5.5 | Infinity | Infinity
5.7 | Infinity | Infinity
5.9 | Infinity | Infinity
6 | 8.75 | 11.5
6 | 9 | 12
6 | 8.75 | 11.5
6 | 9.5 | 13
6 | 8.75 | 11.5
6.1 | 9.05 | 12
6.1 | Infinity | Infinity
6.2 | 8.85 | 11.5
6.3 | Infinity | Infinity
6.5 | 9 | 11.5
6.5 | 9.25 | 12
6.5 | 9.25 | 12
6.5 | Infinity | Infinity
6.6 | Infinity | Infinity
6.7 | 9.1 | 11.5
6.7 | Infinity | Infinity
6.75 | Infinity | Infinity
6.8 | Infinity | Infinity
6.9 | 9.55 | 12.2
6.9 | 48.45 | 90
6.9 | Infinity | Infinity
7 | 9.25 | 11.5
7 | 9.25 | 11.5
7 | 9.25 | 11.5
7 | Infinity | Infinity
7.15 | Infinity | Infinity
7.2 | 10.35 | 13.5
7.3 | 48.65 | 90
7.3 | Infinity | Infinity
7.3 | Infinity | Infinity
7.4 | 9.75 | 12.1
7.4 | Infinity | Infinity
7.5 | 9.5 | 11.5
7.5 | 9.75 | 12
7.5 | Infinity | Infinity
7.7 | 9.6 | 11.5
7.7 | Infinity | Infinity
7.75 | Infinity | Infinity
8 | 9.85 | 11.7
8 | 10 | 12
8 | 10.5 | 13
8.2 | Infinity | Infinity
8.3 | Infinity | Infinity
8.5 | 10 | 11.5
8.5 | 10.5 | 12.5
8.5 | Infinity | Infinity
8.6 | 53.8 | 99
8.7 | 10 | 11.3
8.7 | 10.2 | 11.7
8.9 | 10.2 | 11.5
9 | 10.5 | 12
9 | 10.15 | 11.3
9 | 10.25 | 11.5
9 | 10.5 | 12
9 | Infinity | Infinity
9.2 | 10.6 | 12
9.4 | 10.8 | 12.2
9.5 | 10.75 | 12
9.5 | 10.85 | 12.2
9.5 | Infinity | Infinity
9.6 | 10.55 | 11.5
9.7 | 10.6 | 11.5
9.7 | 10.85 | 12
9.8 | 11.15 | 12.5
10 | 10.8 | 11.6
10 | 10.75 | 11.5
10 | 11.25 | 12.5
10 | 11.25 | 12.5
10.2 | 11 | 11.8
10.5 | 11 | 11.5
10.5 | 11 | 11.5
10.5 | 12 | 13.5
10.7 | 11.5 | 12.3
| |
(144 rows)

View File

@ -35,9 +35,9 @@ extern int seg_yydebug;
*/
SEG *seg_in(char *str);
char *seg_out(SEG * seg);
float32 seg_lower(SEG * seg);
float32 seg_upper(SEG * seg);
float32 seg_center(SEG * seg);
float4 seg_lower(SEG * seg);
float4 seg_upper(SEG * seg);
float4 seg_center(SEG * seg);
/*
** GiST support methods
@ -138,14 +138,14 @@ seg_out(SEG * seg)
{
if (seg->l_ext != '-')
{
/* print the lower boudary if exists */
/* print the lower boundary if exists */
p += restore(p, seg->lower, seg->l_sigd);
p += sprintf(p, " ");
}
p += sprintf(p, "..");
if (seg->u_ext != '-')
{
/* print the upper boudary if exists */
/* print the upper boundary if exists */
p += sprintf(p, " ");
if (seg->u_ext == '>' || seg->u_ext == '<' || seg->l_ext == '~')
p += sprintf(p, "%c", seg->u_ext);
@ -156,40 +156,22 @@ seg_out(SEG * seg)
return (result);
}
float32
float4
seg_center(SEG * seg)
{
float32 result = (float32) palloc(sizeof(float32data));
if (!seg)
return (float32) NULL;
*result = ((float) seg->lower + (float) seg->upper) / 2.0;
return (result);
return ((float) seg->lower + (float) seg->upper) / 2.0;
}
float32
float4
seg_lower(SEG * seg)
{
float32 result = (float32) palloc(sizeof(float32data));
if (!seg)
return (float32) NULL;
*result = (float) seg->lower;
return (result);
return seg->lower;
}
float32
float4
seg_upper(SEG * seg)
{
float32 result = (float32) palloc(sizeof(float32data));
if (!seg)
return (float32) NULL;
*result = (float) seg->upper;
return (result);
return seg->upper;
}

View File

@ -1,4 +1,4 @@
/* $PostgreSQL: pgsql/contrib/seg/seg.sql.in,v 1.17 2008/04/14 17:05:32 tgl Exp $ */
/* $PostgreSQL: pgsql/contrib/seg/seg.sql.in,v 1.18 2008/04/18 18:43:08 alvherre Exp $ */
-- Adjust this setting to control where the objects get created.
SET search_path = public;
@ -164,6 +164,11 @@ LANGUAGE C STRICT IMMUTABLE;
-- miscellaneous
CREATE OR REPLACE FUNCTION seg_center(seg)
RETURNS float4
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;
CREATE OR REPLACE FUNCTION seg_upper(seg)
RETURNS float4
AS 'MODULE_PATHNAME'

View File

@ -1,7 +1,7 @@
typedef struct SEG
{
float lower;
float upper;
float4 lower;
float4 upper;
char l_sigd;
char u_sigd;
char l_ext;

View File

@ -223,3 +223,7 @@ SELECT count(*) FROM test_seg WHERE s @> '11..11.3';
-- Test sorting
SELECT * FROM test_seg WHERE s @> '11..11.3' GROUP BY s;
-- Test functions
SELECT seg_lower(s), seg_center(s), seg_upper(s)
FROM test_seg WHERE s @> '11.2..11.3' OR s IS NULL ORDER BY s;

View File

@ -1,4 +1,4 @@
/* $PostgreSQL: pgsql/contrib/seg/uninstall_seg.sql,v 1.6 2008/04/14 17:05:32 tgl Exp $ */
/* $PostgreSQL: pgsql/contrib/seg/uninstall_seg.sql,v 1.7 2008/04/18 18:43:08 alvherre Exp $ */
-- Adjust this setting to control where the objects get dropped.
SET search_path = public;
@ -51,6 +51,8 @@ DROP OPERATOR <= (seg, seg);
DROP OPERATOR < (seg, seg);
DROP FUNCTION seq_center(seg);
DROP FUNCTION seg_lower(seg);
DROP FUNCTION seg_upper(seg);