42
42
#define PART_RELS_SIZE 10
43
43
#define CHILD_FACTOR 500
44
44
45
-
46
45
/* Storage for PartRelationInfos */
47
46
HTAB * partitioned_rels = NULL ;
48
47
@@ -52,6 +51,9 @@ HTAB *parent_cache = NULL;
52
51
bool initialization_needed = true;
53
52
static bool relcache_callback_needed = true;
54
53
54
+ /* Help user in case of emergency */
55
+ #define INIT_ERROR_HINT "pg_pathman will be disabled to allow you fix this"
56
+
55
57
56
58
static bool init_pathman_relation_oids (void );
57
59
static void fini_pathman_relation_oids (void );
@@ -284,9 +286,13 @@ fill_prel_with_partitions(const Oid *partitions,
284
286
if (validate_hash_constraint (con_expr ,prel ,& hash ))
285
287
prel -> children [hash ]= partitions [i ];
286
288
else
287
- elog (ERROR ,
288
- "Wrong constraint format for HASH partition \"%s\"" ,
289
- get_rel_name_or_relid (partitions [i ]));
289
+ {
290
+ DisablePathman ();/* disable pg_pathman since config is broken */
291
+ ereport (ERROR ,
292
+ (errmsg ("Wrong constraint format for HASH partition \"%s\"" ,
293
+ get_rel_name_or_relid (partitions [i ])),
294
+ errhint (INIT_ERROR_HINT )));
295
+ }
290
296
}
291
297
break ;
292
298
@@ -302,15 +308,24 @@ fill_prel_with_partitions(const Oid *partitions,
302
308
prel -> ranges [i ].max = range_max ;
303
309
}
304
310
else
305
- elog (ERROR ,
306
- "Wrong constraint format for RANGE partition \"%s\"" ,
307
- get_rel_name_or_relid (partitions [i ]));
311
+ {
312
+ DisablePathman ();/* disable pg_pathman since config is broken */
313
+ ereport (ERROR ,
314
+ (errmsg ("Wrong constraint format for RANGE partition \"%s\"" ,
315
+ get_rel_name_or_relid (partitions [i ])),
316
+ errhint (INIT_ERROR_HINT )));
317
+ }
308
318
}
309
319
break ;
310
320
311
321
default :
312
- elog (ERROR ,"Unknown partitioning type for relation \"%s\"" ,
313
- get_rel_name_or_relid (prel -> key ));
322
+ {
323
+ DisablePathman ();/* disable pg_pathman since config is broken */
324
+ ereport (ERROR ,
325
+ (errmsg ("Unknown partitioning type for relation \"%s\"" ,
326
+ get_rel_name_or_relid (prel -> key )),
327
+ errhint (INIT_ERROR_HINT )));
328
+ }
314
329
}
315
330
}
316
331
@@ -350,9 +365,12 @@ fill_prel_with_partitions(const Oid *partitions,
350
365
for (i = 0 ;i < PrelChildrenCount (prel );i ++ )
351
366
{
352
367
if (prel -> children [i ]== InvalidOid )
368
+ {
369
+ DisablePathman ();/* disable pg_pathman since config is broken */
353
370
elog (ERROR ,"pg_pathman's cache for relation \"%s\" "
354
371
"has not been properly initialized" ,
355
372
get_rel_name_or_relid (prel -> key ));
373
+ }
356
374
}
357
375
#endif
358
376
}
@@ -605,11 +623,10 @@ read_pathman_config(void)
605
623
if (get_rel_type_id (relid )== InvalidOid )
606
624
{
607
625
DisablePathman ();/* disable pg_pathman since config is broken */
608
-
609
626
ereport (ERROR ,
610
627
(errmsg ("Table \"%s\" contains nonexistent relation %u" ,
611
628
PATHMAN_CONFIG ,relid ),
612
- errdetail ( "pg_pathman will be disabled" )));
629
+ errhint ( INIT_ERROR_HINT )));
613
630
}
614
631
615
632
/* Create or update PartRelationInfo for this partitioned table */
@@ -638,17 +655,30 @@ get_partition_constraint_expr(Oid partition, AttrNumber part_attno)
638
655
Expr * expr ;/* expression tree for constraint */
639
656
640
657
conname = build_check_constraint_name_internal (partition ,part_attno );
641
- conid = get_relation_constraint_oid (partition ,conname , false);
658
+ conid = get_relation_constraint_oid (partition ,conname , true);
659
+ if (conid == InvalidOid )
660
+ {
661
+ DisablePathman ();/* disable pg_pathman since config is broken */
662
+ ereport (ERROR ,
663
+ (errmsg ("constraint \"%s\" for partition \"%s\" does not exist" ,
664
+ conname ,get_rel_name_or_relid (partition )),
665
+ errhint (INIT_ERROR_HINT )));
666
+ }
642
667
643
668
con_tuple = SearchSysCache1 (CONSTROID ,ObjectIdGetDatum (conid ));
644
669
conbin_datum = SysCacheGetAttr (CONSTROID ,con_tuple ,
645
670
Anum_pg_constraint_conbin ,
646
671
& conbin_isnull );
647
672
if (conbin_isnull )
648
673
{
649
- elog (DEBUG2 ,"conbin is null for constraint %s" ,conname );
674
+ DisablePathman ();/* disable pg_pathman since config is broken */
675
+ ereport (WARNING ,
676
+ (errmsg ("constraint \"%s\" for partition \"%s\" has NULL conbin" ,
677
+ conname ,get_rel_name_or_relid (partition )),
678
+ errhint (INIT_ERROR_HINT )));
650
679
pfree (conname );
651
- return NULL ;
680
+
681
+ return NULL ;/* could not parse */
652
682
}
653
683
pfree (conname );
654
684
@@ -690,6 +720,9 @@ validate_range_constraint(const Expr *expr,
690
720
const BoolExpr * boolexpr = (const BoolExpr * )expr ;
691
721
const OpExpr * opexpr ;
692
722
723
+ if (!expr )
724
+ return false;
725
+
693
726
/* it should be an AND operator on top */
694
727
if (!and_clause ((Node * )expr ))
695
728
return false;
@@ -779,6 +812,9 @@ validate_hash_constraint(const Expr *expr,
779
812
* type_hash_proc_expr ;
780
813
const Var * var ;/* partitioned column */
781
814
815
+ if (!expr )
816
+ return false;
817
+
782
818
if (!IsA (expr ,OpExpr ))
783
819
return false;
784
820
eq_expr = (const OpExpr * )expr ;
@@ -825,7 +861,7 @@ validate_hash_constraint(const Expr *expr,
825
861
return false;
826
862
827
863
/* Check that PARTITIONS_COUNT is equal to total amount of partitions */
828
- if (DatumGetUInt32 (((Const * )second )-> constvalue )!= PrelChildrenCount (prel ))
864
+ if (DatumGetUInt32 (((Const * )second )-> constvalue )!= PrelChildrenCount (prel ))
829
865
return false;
830
866
831
867
/* Check that CUR_PARTITION_HASH is Const */