Skip to content

Commit 588b292

Browse files
committed
fix sigfault when inserting into area not covered with partitions and interval set to NULL
1 parent 3bc9643 commit 588b292

File tree

2 files changed

+42
-24
lines changed

2 files changed

+42
-24
lines changed

init.sql

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,40 @@ END
596596
$$ LANGUAGE plpgsql STRICT;
597597

598598

599+
/*
600+
* Set new relname, schema and tablespace
601+
*/
602+
CREATE OR REPLACE FUNCTION @extschema@.alter_partition(relation REGCLASS,
603+
new_name TEXT,
604+
new_schema REGNAMESPACE,
605+
new_tablespace TEXT)
606+
RETURNS VOID AS
607+
$$
608+
DECLARE
609+
orig_name TEXT;
610+
orig_schema OID;
611+
BEGIN
612+
SELECT relname, relnamespace FROM pg_class WHERE oid = relation
613+
INTO orig_name, orig_schema;
614+
615+
/* Alter table name */
616+
IF new_name != orig_name THEN
617+
EXECUTE format('ALTER TABLE %s RENAME TO %s', relation, new_name);
618+
END IF;
619+
620+
/* Alter table schema */
621+
IF new_schema != orig_schema THEN
622+
EXECUTE format('ALTER TABLE %s SET SCHEMA %s', relation, new_schema);
623+
END IF;
624+
625+
/* Move to another tablespace */
626+
IF NOT new_tablespace IS NULL THEN
627+
EXECUTE format('ALTER TABLE %s SET TABLESPACE %s', relation, new_tablespace);
628+
END IF;
629+
END
630+
$$ LANGUAGE plpgsql;
631+
632+
599633
/*
600634
* Partitioning key
601635
*/

src/partition_creation.c

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -363,43 +363,27 @@ create_partitions_for_value_internal(Oid relid, Datum value, Oid value_type)
363363
RangeEntry *ranges = PrelGetRangesArray(prel);
364364
Datum bound_min, /* absolute MIN */
365365
bound_max; /* absolute MAX */
366-
// Infinitable bound_min, /* lower bound of all partitions */
367-
// bound_max; /* upper bound of all partitions */
368-
// Infinitable start,
369-
// end;
370366

371367
Oid interval_type = InvalidOid;
372368
Datum interval_binary, /* assigned 'width' of one partition */
373369
interval_text;
374370

375-
// bound_min = ranges[0].min;
376-
// bound_max = ranges[PrelLastChild(prel)].max;
377-
378-
// start.value = !IsInfinite(&bound_min) ?
379-
// datumCopy(InfinitableGetValue(&bound_min),
380-
// prel->attbyval,
381-
// prel->attlen) :
382-
// (Datum) 0;
383-
// start.is_infinite = IsInfinite(&bound_min);
384-
385-
// end.value = !IsInfinite(&bound_max) ?
386-
// datumCopy(InfinitableGetValue(&bound_max),
387-
// prel->attbyval,
388-
// prel->attlen) :
389-
// (Datum) 0;
390-
// end.is_infinite = IsInfinite(&bound_max);
391-
392371
/* Read max & min range values from PartRelationInfo */
393-
/* TODO */
394-
// bound_min = PrelGetRangesArray(prel)[0].min;
395-
// bound_max = PrelGetRangesArray(prel)[PrelLastChild(prel)].max;
396372
bound_min = BoundGetValue(&ranges[0].min);
397373
bound_max = BoundGetValue(&ranges[PrelLastChild(prel)].max);
398374

399375
/* Copy datums on order to protect them from cache invalidation */
400376
bound_min = datumCopy(bound_min, prel->attbyval, prel->attlen);
401377
bound_max = datumCopy(bound_max, prel->attbyval, prel->attlen);
402378

379+
/* Check if interval is set */
380+
if (isnull[Anum_pathman_config_range_interval - 1])
381+
{
382+
elog(ERROR,
383+
"Could not find appropriate partition for key '%s'",
384+
datum_to_cstring(value, value_type));
385+
}
386+
403387
/* Retrieve interval as TEXT from tuple */
404388
interval_text = values[Anum_pathman_config_range_interval - 1];
405389

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy