Skip to content

Single parsing for MEOS values#754

Merged
mschoema merged 2 commits intoMobilityDB:masterfrom
estebanzimanyi:single_parsing
Feb 17, 2026
Merged

Single parsing for MEOS values#754
mschoema merged 2 commits intoMobilityDB:masterfrom
estebanzimanyi:single_parsing

Conversation

@estebanzimanyi
Copy link
Copy Markdown
Member

This PR enables a single parsing for MEOS values using an expandable array.

When parsing a value composed of other values, such as a temporal sequence composed of temporal instants, at the beginning we don't know the number of composing values in the text string. Previously we parsed once the string, and after knowing the number of values, we create an array for holding the values with a palloc and then, the string was reparsed again saving the values in the array. The new expandable array data structure enables a single parsing.

@mschoema
Copy link
Copy Markdown
Member

mschoema commented Feb 1, 2026

Similar question as the Oid PR. Are there any benchmarks showing improvements from this PR? This PR is a pit risky if the repeated allocations slow things down. Code looks good, but I'll wait a bit before merging to be sure things did not slow down.

@estebanzimanyi
Copy link
Copy Markdown
Member Author

estebanzimanyi commented Feb 5, 2026

I created a table with 1,000 tgeompoint values of 1,000 instants each where the values are stored as text in EWKT format.

DROP TABLE IF EXISTS Tgeompoint_1K_1K;
CREATE TABLE Tgeompoint_1K_1K(Id, value) AS
SELECT k, asEWKT(tgeompointSeq(array_agg(tgeompoint(ST_Point(i % 2, i % 2, 5676), timestamptz '2001-01-01' + i * interval '1 minute'))))
FROM generate_series(1, 1000) k, generate_series(1, 1000) i
GROUP BY k;

I created the following query.sql file

SELECT st_makepoint(1,1); SELECT MAX(numInstants(value::tgeompoint)) FROM Tgeompoint_1K_1K;

where the first SELECT is simply to load the MobilityDB library in memory and the second one parse the text values to create the temporal points and then applies to them the method numInstants.

I ran valgrind testing the above file

valgrind --tool=callgrind postgres --single test < query.sql

with and without the PR and kcachegrind shows that the PR divided by 2 the number of calls for the functions creating the temporal points.

Current code

image

With the PR

image

In psql I run the same query on a table Tgeompoint_1K_100K, thus containing 1,000 tgeompoint values of 100,000 instants each.

Current code

test=# \timing
Timing is on.
test=# SELECT MAX(numInstants(value::tgeompoint)) FROM Tgeompoint_1K_100K;
  max
--------
 100000
(1 row)

Time: 320154.937 ms (05:20.155)

With the PR

test=# \timing
Timing is on.
test=# SELECT MAX(numInstants(value::tgeompoint)) FROM Tgeompoint_1K_100K;
  max
--------
 100000
(1 row)

Time: 175716.412 ms (02:55.716)

@mschoema
Copy link
Copy Markdown
Member

mschoema commented Feb 6, 2026

That looks great ! This is a big improvement compared to the double parsing

Copy link
Copy Markdown
Member

@mschoema mschoema left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but there's just a small thing to fix that was reported by codacy

@mschoema mschoema merged commit e92f1ce into MobilityDB:master Feb 17, 2026
18 checks passed
@mschoema mschoema deleted the single_parsing branch February 17, 2026 14:50
estebanzimanyi added a commit to estebanzimanyi/MobilityDB that referenced this pull request Mar 25, 2026
PR MobilityDB#754 added the MeosArray data type for enabling a single-parsing of temporal values.
This PR enables single-parsing of spanset types. For this, we enabled a MeosArray to
store fixed-length structures.
estebanzimanyi added a commit to estebanzimanyi/MobilityDB that referenced this pull request Mar 25, 2026
PR MobilityDB#754 added the MeosArray data type for enabling a single-parsing of temporal values.
This PR enables single-parsing of spanset types. For this, we enabled a MeosArray to
store fixed-length structures.
estebanzimanyi added a commit to estebanzimanyi/MobilityDB that referenced this pull request Mar 25, 2026
PR MobilityDB#754 added the MeosArray data type for enabling a single-parsing of temporal values.
This PR enables single-parsing of spanset types. For this, we enabled a MeosArray to
store fixed-length structures.
estebanzimanyi added a commit to estebanzimanyi/MobilityDB that referenced this pull request Mar 25, 2026
PR MobilityDB#754 added the MeosArray data type for enabling a single-parsing of temporal values.
This PR enables single-parsing of spanset types. For this, we enabled a MeosArray to
store fixed-length structures.
estebanzimanyi added a commit to estebanzimanyi/MobilityDB that referenced this pull request Mar 25, 2026
PR MobilityDB#754 added the MeosArray data type for enabling a single-parsing of temporal values.
This PR enables single-parsing of spanset types. For this, we enabled a MeosArray to
store fixed-length structures.

This PR also enables a faster version of the PostGIS function ST_MinimumBounding where
the array collects the points of a geometry minimizing memory allocation.
This will be added in a subsequent PR.
estebanzimanyi added a commit to estebanzimanyi/MobilityDB that referenced this pull request Mar 25, 2026
PR MobilityDB#754 added the MeosArray data type for enabling a single-parsing of temporal values.
This PR enables single-parsing of spanset types. For this, we enabled a MeosArray to
store fixed-length structures.

This PR also enables a faster version of the PostGIS function ST_MinimumBounding where
the array collects the points of a geometry minimizing memory allocation.
This will be added in a subsequent PR.
estebanzimanyi added a commit to estebanzimanyi/MobilityDB that referenced this pull request Mar 25, 2026
PR MobilityDB#754 added the MeosArray data type for enabling a single-parsing of temporal values.
This PR enables single-parsing of spanset types. For this, we enabled a MeosArray to
store fixed-length structures.

This PR also enables a faster version of the PostGIS function ST_MinimumBounding where
the array collects the points of a geometry minimizing memory allocation.
This will be added in a subsequent PR.
estebanzimanyi added a commit to estebanzimanyi/MobilityDB that referenced this pull request Mar 25, 2026
PR MobilityDB#754 added the MeosArray data type for enabling a single-parsing of temporal values.
This PR enables single-parsing of spanset types. For this, we enabled a MeosArray to
store fixed-length structures.

This PR also enables a faster version of the PostGIS function ST_MinimumBounding where
the array collects the points of a geometry minimizing memory allocation.
This will be added in a subsequent PR.
estebanzimanyi added a commit to estebanzimanyi/MobilityDB that referenced this pull request Mar 26, 2026
PR MobilityDB#754 added the MeosArray data type for enabling a single-parsing of temporal values.
This PR enables single-parsing of spanset types. For this, we enabled a MeosArray to
store fixed-length structures.

This PR also enables a faster version of the PostGIS function ST_MinimumBounding where
the array collects the points of a geometry minimizing memory allocation.
This will be added in a subsequent PR.
estebanzimanyi added a commit to estebanzimanyi/MobilityDB that referenced this pull request Mar 26, 2026
PR MobilityDB#754 added the MeosArray data type for enabling a single-parsing of temporal values.
This PR enables single-parsing of spanset types. For this, we enabled a MeosArray to
store fixed-length structures.

This PR also enables a faster version of the PostGIS function ST_MinimumBounding where
the array collects the points of a geometry minimizing memory allocation.
This will be added in a subsequent PR.
estebanzimanyi added a commit to estebanzimanyi/MobilityDB that referenced this pull request Mar 26, 2026
PR MobilityDB#754 added the MeosArray data type for enabling a single-parsing of temporal values.
This PR enables single-parsing of spanset types. For this, we enabled a MeosArray to
store fixed-length structures.

This PR also enables a faster version of the PostGIS function ST_MinimumBounding where
the array collects the points of a geometry minimizing memory allocation.
This will be added in a subsequent PR.
estebanzimanyi added a commit to estebanzimanyi/MobilityDB that referenced this pull request Mar 26, 2026
PR MobilityDB#754 added the MeosArray data type for enabling a single-parsing of temporal values.
This PR enables single-parsing of spanset types. For this, we enabled a MeosArray to
store fixed-length structures.

This PR also enables a faster version of the PostGIS function ST_MinimumBounding where
the array collects the points of a geometry minimizing memory allocation.
This will be added in a subsequent PR.
estebanzimanyi added a commit to estebanzimanyi/MobilityDB that referenced this pull request Mar 27, 2026
PR MobilityDB#754 added the MeosArray data type for enabling a single-parsing of temporal values.
This PR enables single-parsing of spanset types. For this, we enabled a MeosArray to
store fixed-length structures.

This PR also enables a faster version of the PostGIS function ST_MinimumBounding where
the array collects the points of a geometry minimizing memory allocation.
This will be added in a subsequent PR.
estebanzimanyi added a commit to estebanzimanyi/MobilityDB that referenced this pull request Mar 30, 2026
PR MobilityDB#754 added the MeosArray data type for enabling a single-parsing of temporal values.
This PR enables single-parsing of spanset types. For this, we enabled a MeosArray to
store fixed-length structures.

This PR also enables a faster version of the PostGIS function ST_MinimumBounding where
the array collects the points of a geometry minimizing memory allocation.
This will be added in a subsequent PR.
estebanzimanyi added a commit to estebanzimanyi/MobilityDB that referenced this pull request Mar 31, 2026
PR MobilityDB#754 added the MeosArray data type for enabling a single-parsing of temporal values.
This PR enables single-parsing of spanset types. For this, we enabled a MeosArray to
store fixed-length structures.

This PR also enables a faster version of the PostGIS function ST_MinimumBounding where
the array collects the points of a geometry minimizing memory allocation.
This will be added in a subsequent PR.
estebanzimanyi added a commit to estebanzimanyi/MobilityDB that referenced this pull request Mar 31, 2026
PR MobilityDB#754 added the MeosArray data type for enabling a single-parsing of temporal values.
This PR enables single-parsing of spanset types. For this, we enabled a MeosArray to
store fixed-length structures.

This PR also enables a faster version of the PostGIS function ST_MinimumBounding where
the array collects the points of a geometry minimizing memory allocation.
This will be added in a subsequent PR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants