Quelle spatial_utility_function_collect.result
Sprache: Lisp
# setup of data for tests involving simple aggregations and group by
CREATE TABLE table_simple_aggregation ( running_number INTEGER NOT NULL
AUTO_INCREMENT, grouping_condition INTEGER, location GEOMETRY , PRIMARY KEY (
running_number));
INSERT INTO table_simple_aggregation ( grouping_condition, location ) VALUES
( 0,ST_GEOMFROMTEXT('POINT(0 0)',4326)),
( 1,ST_GEOMFROMTEXT('POINT(0 0)',4326)),
( 0,ST_GEOMFROMTEXT('POINT(1 0)',4326)),
( 1,ST_GEOMFROMTEXT('POINT(2 0)',4326)),
( 0,ST_GEOMFROMTEXT('POINT(3 0)',4326));
# Functional requirement F-4: ST_COLLECT shall support simple table
# aggregations
# result shall be 1
SELECT ST_EQUALS( (SELECT ST_COLLECT( location ) AS t FROM
table_simple_aggregation) , ST_GEOMFROMTEXT('MULTIPOINT(0 0,0 0,1 0,2 0,30) ',4326)) c;
c 1
# Functional requirement F-8 Shall support DISTINCT in aggregates
# result shall be 1
SELECT ST_EQUALS( (SELECT ST_COLLECT( DISTINCT location ) AS t FROM
table_simple_aggregation) , ST_GEOMFROMTEXT('MULTIPOINT(0 0,1 0,2 0,3 0) ',4326)) c;
c 1
# Functional requirement F-5: ST_COLLECT shall support group by, which
# is given by aggregation machinery
# result shall be
# MULTIPOINT(00,10,30)
# MULTIPOINT(20,00)
SELECT ST_ASTEXT(ST_COLLECT( DISTINCT location )) AS t FROM
table_simple_aggregation GROUP BY grouping_condition;
t
MULTIPOINT(00,10,30)
MULTIPOINT(00,20)
INSERT INTO table_simple_aggregation (location) VALUES
( ST_GEOMFROMTEXT('POINT(0 -0)' ,4326)),
( NULL);
# F-7 Aggregations with Nulls inside will just miss an element for each
# Null
# the result here shall be 1
SELECT ST_EQUALS((SELECT ST_COLLECT(LOCATION) AS T FROM
table_simple_aggregation), ST_GEOMFROMTEXT('GEOMETRYCOLLECTION( MULTIPOINT(0 0,10,30), MULTIPOINT(20,00), POINT(00))',4326)) c;
c 1
# F-1 ST_COLLECT SHALL only return NULL if all elements are NULL or the
# aggregate is empty.
# as only a null is aggregated the result of the subquery shall be NULL
# and the result of the whole query shall be 1
SELECT (SELECT ST_COLLECT(location) AS t FROM table_simple_aggregation WHERE
location = NULL) IS NULL c;
c 1
# as no element is aggregated the result of the subquery shall be NULL
# and the result of the whole query shall be 1
SELECT (SELECT ST_COLLECT(location) AS t FROM table_simple_aggregation WHERE
st_srid(location)=2110) IS NULL c;
c 1
INSERT INTO table_simple_aggregation (location) VALUES
( ST_GEOMFROMTEXT('POINT(0 -0)' ,4326)),
( NULL),
( NULL);
SELECT ST_ASTEXT(ST_COLLECT(location) OVER ( ROWS BETWEEN 1 PRECEDING AND
CURRENT ROW)) c FROM table_simple_aggregation;
c
MULTIPOINT(00)
MULTIPOINT(00,00)
MULTIPOINT(00,10)
MULTIPOINT(10,20)
MULTIPOINT(20,30)
MULTIPOINT(30,00)
MULTIPOINT(00)
MULTIPOINT(00)
MULTIPOINT(00)
NULL
Excercising multiple code paths.
SELECT ST_ASTEXT(ST_COLLECT(DISTINCT location)) AS geo, SUM(running_number)
OVER() FROM table_simple_aggregation GROUP BY running_number;
geo SUM(running_number)
OVER()
MULTIPOINT(00) 55
MULTIPOINT(00) 55
MULTIPOINT(00) 55
MULTIPOINT(00) 55
MULTIPOINT(10) 55
MULTIPOINT(20) 55
MULTIPOINT(30) 55
NULL 55
NULL 55
NULL 55
# remove disable_view_protocol after fixing MDEV-36695
SELECT ST_ASTEXT(ST_COLLECT(DISTINCT location)) AS geo, SUM(grouping_condition)
OVER(), grouping_condition FROM table_simple_aggregation GROUP BY
grouping_condition;
geo SUM(grouping_condition)
OVER() grouping_condition
MULTIPOINT(00) 1 NULL
MULTIPOINT(00,10,30) 10
MULTIPOINT(00,20) 11
SELECT ST_ASTEXT(ST_COLLECT(location)) AS geo, SUM(grouping_condition) OVER(),
grouping_condition FROM table_simple_aggregation GROUP BY grouping_condition;
geo SUM(grouping_condition) OVER() grouping_condition
MULTIPOINT(00,00) 1 NULL
MULTIPOINT(00,10,30) 10
MULTIPOINT(00,20) 11
SELECT ST_ASTEXT(ST_COLLECT(location)) AS geo, SUM(running_number) OVER() FROM
table_simple_aggregation GROUP BY running_number;
geo SUM(running_number) OVER()
MULTIPOINT(00) 55
MULTIPOINT(00) 55
MULTIPOINT(00) 55
MULTIPOINT(00) 55
MULTIPOINT(10) 55
MULTIPOINT(20) 55
MULTIPOINT(30) 55
NULL 55
NULL 55
NULL 55 set session group_concat_max_len= 10;
SELECT ST_COLLECT( location ) AS t FROM table_simple_aggregation;
t
NULL
Warnings:
Warning 1260 Row 1 was cut by st_collect() set session group_concat_max_len= 1048576;
# Teardown of testing NULL data
DROP TABLE table_simple_aggregation;
# Setup for testing handling of multiple SRS
CREATE TABLE multi_srs_table ( running_number INTEGER NOT NULL AUTO_INCREMENT,
geometry GEOMETRY , PRIMARY KEY ( running_number ));
INSERT INTO multi_srs_table( geometry ) VALUES
(ST_GEOMFROMTEXT('POINT(60 -24)' ,4326)),
(ST_GEOMFROMTEXT('POINT(61 -24)' ,4326)),
(ST_GEOMFROMTEXT('POINT(38 77)'));
# F-2 a) If the elements in an aggregate is of different SRSs,
# ST_COLLECT MUST raise ER_GIS_DIFFERENT_SRIDS.
SELECT ST_ASTEXT(ST_COLLECT(geometry)) AS t FROM multi_srs_table; ERROR HY000: Arguments to function st_collect( contains geometries with different SRIDs: 4326and0. All geometries must have the same SRID.
# F-2 b) If all the elements in an aggregate is of same SRS, ST_COLLECT
# MUST return a result in that SRS.
# result shall be one MULTIPOINT((60 -24),(61 -24)) with SRID 4326and
# one
# Multipoint((3877)) with SRID 0. There is some rounding issue on the
# result, bug #31535105
SELECT st_srid(geometry),ST_ASTEXT(ST_COLLECT( geometry )) AS t FROM
multi_srs_table GROUP BY ST_SRID(geometry);
st_srid(geometry) t 0 MULTIPOINT(3877) 4326 MULTIPOINT(60 -24,61 -24)
Rollup needs all SRIDs to be the same.
SELECT st_srid(geometry),ST_ASTEXT(ST_COLLECT( geometry )) AS t FROM
multi_srs_table GROUP BY ST_SRID(geometry) WITH ROLLUP; ERROR HY000: Arguments to function st_collect( contains geometries with different SRIDs: 0and4326. All geometries must have the same SRID.
# Triggering a codepath for geometrycollection in temp tables
INSERT INTO multi_srs_table( geometry ) VALUES
(ST_GEOMFROMTEXT('GEOMETRYCOLLECTION(POINT(60 -24))' ,4326));
SELECT st_srid(geometry),ST_ASTEXT( geometry ) AS t FROM
multi_srs_table GROUP BY ST_SRID(geometry);
st_srid(geometry) t 0 POINT(3877) 4326 POINT(60 -24)
#teardown of testing handling of multiple SRS
DROP TABLE multi_srs_table;
# setup of testing handling different geometry types
CREATE TABLE simple_table ( running_number INTEGER NOT NULL AUTO_INCREMENT ,
geo GEOMETRY, PRIMARY KEY ( RUNNING_NUMBER));
INSERT INTO simple_table ( geo) VALUES
(ST_GEOMFROMTEXT('POINT(0 0)')),
(ST_GEOMFROMTEXT('LINESTRING(1 0, 1 1)')),
(ST_GEOMFROMTEXT('LINESTRING(2 0, 2 1)')),
(ST_GEOMFROMTEXT('POLYGON((3 0, 0 0, 0 3, 3 3, 3 0))')),
(ST_GEOMFROMTEXT('POLYGON((4 0, 0 0, 0 4, 4 4, 4 0))')),
(ST_GEOMFROMTEXT('MULTIPOINT(5 0)')),
(ST_GEOMFROMTEXT('MULTIPOINT(6 0)')),
(ST_GEOMFROMTEXT('GEOMETRYCOLLECTION EMPTY')),
(ST_GEOMFROMTEXT('GEOMETRYCOLLECTION EMPTY'));
# Functional requirement F-9 a, b, and c ) An aggregation containing
# more than one type of geometry or any MULTI is GEOMETRYCOLLECTION, if
# it only contains a single type of POINTS, LINESTRINGS or POLYGONS it
# will be a MULTI of the same kind.
# MP: Multipoint
# MPoly: Multipolygon
# MLS: Multilinestring
# GC: geometrycollection
# Functional requirement F-6 shall support window functions
# result is expected for come in this order: MP, GC, MLS, GC, MPpoly,
# GC, GC, GC, GC
SELECT ST_ASTEXT(ST_COLLECT(geo) OVER( ORDER BY running_number ROWS BETWEEN 1
PRECEDING AND CURRENT ROW)) AS geocollect FROM simple_table;
geocollect
MULTIPOINT(00)
GEOMETRYCOLLECTION(POINT(00),LINESTRING(10,11))
MULTILINESTRING((10,11),(20,21))
GEOMETRYCOLLECTION(LINESTRING(20,21),POLYGON((30,00,03,33,30)))
MULTIPOLYGON(((30,00,03,33,30)),((40,00,04,44,40)))
GEOMETRYCOLLECTION(POLYGON((40,00,04,44,40)),MULTIPOINT(50))
GEOMETRYCOLLECTION(MULTIPOINT(50),MULTIPOINT(60))
GEOMETRYCOLLECTION(MULTIPOINT(60),GEOMETRYCOLLECTION EMPTY)
GEOMETRYCOLLECTION(GEOMETRYCOLLECTION EMPTY,GEOMETRYCOLLECTION EMPTY)
# with DISTINCT this result is expected to be:
# MP, GC, MLS, GC, MPpoly, GC, GC, GC, GC with only one EMPTY GC
# remove disable_view_protocol after fixing MDEV-36695
SELECT ST_ASTEXT(ST_COLLECT(DISTINCT geo) OVER( ORDER BY running_number ROWS BETWEEN 1
PRECEDING AND CURRENT ROW)) AS geocollect FROM simple_table;
geocollect
MULTIPOINT(00)
GEOMETRYCOLLECTION(POINT(00),LINESTRING(10,11))
MULTILINESTRING((10,11),(20,21))
GEOMETRYCOLLECTION(LINESTRING(20,21),POLYGON((30,00,03,33,30)))
MULTIPOLYGON(((30,00,03,33,30)),((40,00,04,44,40)))
GEOMETRYCOLLECTION(POLYGON((40,00,04,44,40)),MULTIPOINT(50))
GEOMETRYCOLLECTION(MULTIPOINT(50),MULTIPOINT(60))
GEOMETRYCOLLECTION(MULTIPOINT(60),GEOMETRYCOLLECTION EMPTY)
GEOMETRYCOLLECTION(GEOMETRYCOLLECTION EMPTY)
# Exercising the "copy" constructor
SELECT ST_ASTEXT(ST_COLLECT(geo)) FROM simple_table GROUP BY geo WITH ROLLUP;
ST_ASTEXT(ST_COLLECT(geo))
MULTIPOINT(00)
MULTILINESTRING((20,21))
MULTILINESTRING((10,11))
MULTIPOLYGON(((30,00,03,33,30)))
MULTIPOLYGON(((40,00,04,44,40)))
GEOMETRYCOLLECTION(MULTIPOINT(50))
GEOMETRYCOLLECTION(MULTIPOINT(60))
GEOMETRYCOLLECTION(GEOMETRYCOLLECTION EMPTY,GEOMETRYCOLLECTION EMPTY)
GEOMETRYCOLLECTION(POINT(00),LINESTRING(20,21),LINESTRING(10,11),POLYGON((30,00,03,33,30)),POLYGON((40,00,04,44,40)),MULTIPOINT(50),MULTIPOINT(60),GEOMETRYCOLLECTION EMPTY,GEOMETRYCOLLECTION EMPTY)
# Casting Geometry as decimal invokes val_decimal()
SELECT CAST(ST_COLLECT(geo) AS DECIMAL ) FROM simple_table; ERROR HY000: Illegal parameter data type geometry for operation 'decimal_typecast'
DROP TABLE simple_table;
#
# MDEV-35102 CREATE TABLE AS SELECT ST_collect ... does not work
#
SELECT ST_astext(ST_collect(( POINTFROMTEXT(' POINT( 4 1 ) ') )));
ST_astext(ST_collect(( POINTFROMTEXT(' POINT( 4 1 ) ') )))
MULTIPOINT(41)
CREATE TABLE tb1 AS SELECT (ST_collect(( POINTFROMTEXT(' POINT( 4 1 ) ') )) );
DROP TABLE tb1;
#
# MDEV-35975 Server crashes after CREATE VIEW as SELECT ST_COLLECT
#
create view v1 as SELECT ST_COLLECT(ST_GEOMFROMTEXT('POINT(0 0)'));
drop view v1;
create view v1 as SELECT GROUP_CONCAT(ST_GEOMFROMTEXT('POINT(0 0)'));
drop view v1;
#
# MDEV-36167 Assertion `0' failed in Item_sum_str::reset_field after selecting st_collect + group by
#
CREATE TABLE t1 (a int, p point);
INSERT INTO t1 (a, p) VALUES (0,st_geomfromtext('POINT(1 1)')), ( 1,st_geomfromtext('POINT(0 0)')), ( 0,st_geomfromtext('POINT(1 1)'));
SELECT st_astext(ST_COLLECT(p)) FROM t1 GROUP BY a;
st_astext(ST_COLLECT(p))
MULTIPOINT(11,11)
MULTIPOINT(00)
DROP TABLE t1;
#
# MDEV-36491 Server crashes in Item_func_group_concat::print
#
SELECT 1 FROM dual WHERE group_concat(1, 1); ERROR HY000: Invalid use of group function
# End of 12.0 tests
#
# MDEV-38755 ST_COLLECT(1) IS NULL is false
#
select st_collect(1), st_collect(1) is null;
st_collect(1) st_collect(1) is null
NULL 1
# End of 12.2 tests
#
# MDEV-39523 UBSAN on ST_COLLECT (has_cached_value)
#
CREATE TABLE t (c INT);
SELECT ST_COLLECT(c) FROM t;
ST_COLLECT(c)
NULL
SELECT ST_ASTEXT(ST_ENVELOPE(ST_COLLECT(c))) FROM t;
ST_ASTEXT(ST_ENVELOPE(ST_COLLECT(c)))
NULL
DROP TABLE t;
#
# MDEV-38669 ST_COLLECT reads past the end of a non-geometry argument
#
SELECT ST_COLLECT('');
ST_COLLECT('')
NULL
SELECT ST_COLLECT('') IS NULL;
ST_COLLECT('') IS NULL 1
SELECT ST_COLLECT('not wkb');
ST_COLLECT('not wkb')
NULL
CREATE TABLE t1 (a VARCHAR(16));
INSERT INTO t1 VALUES (''), ('not wkb'), (NULL);
SELECT ST_COLLECT(a) FROM t1;
ST_COLLECT(a)
NULL
DROP TABLE t1;
# End of 12.3 tests
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet am 2026-10-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.