diff --git a/meos/src/general/type_out.c b/meos/src/general/type_out.c index c3cadb0579..350ca30fec 100644 --- a/meos/src/general/type_out.c +++ b/meos/src/general/type_out.c @@ -848,7 +848,7 @@ tsequenceset_mfjson_size(const TSequenceSet *ss, bool isgeo, bool hasz, size += ( isgeo ? sizeof("{'coordinates':[],") : sizeof("{'values':[],") ) * ss->count; size += sizeof("'datetimes':[],'lower_inc':false,'upper_inc':false},") * ss->count; if (isgeo) - size = coordinates_mfjson_size(ss->totalcount, hasz, precision); + size += coordinates_mfjson_size(ss->totalcount, hasz, precision); else { for (int i = 0; i < ss->count; i++) diff --git a/mobilitydb/src/general/span_selfuncs.c b/mobilitydb/src/general/span_selfuncs.c index 0552632ae2..58ad132ed6 100644 --- a/mobilitydb/src/general/span_selfuncs.c +++ b/mobilitydb/src/general/span_selfuncs.c @@ -366,7 +366,7 @@ calc_length_hist_frac(Datum *hist_length, int hist_length_nvalues, * @brief Estimate the fraction of values less than (or equal to, if 'equal' * argument is true) a given const in a histogram of span bounds */ -static double +static Selectivity span_sel_scalar(const SpanBound *constbound, const SpanBound *hist, int nhist, bool equal) { @@ -400,7 +400,7 @@ span_sel_scalar(const SpanBound *constbound, const SpanBound *hist, * The caller already constructed the singular span from the element * constant, so just treat it the same as &&. */ -static double +static Selectivity span_sel_overlaps(const SpanBound *const_lower, const SpanBound *const_upper, const SpanBound *hist_lower, const SpanBound *hist_upper, int nhist) { @@ -418,11 +418,11 @@ span_sel_overlaps(const SpanBound *const_lower, const SpanBound *const_upper, * Sel = 1.0 - ( Sel(upper(A) < lower(B)) + ( 1 - Sel(lower(A) <= upper(B)) ) ) */ //EZ - // double selec = span_sel_scalar(const_upper, hist_lower, nhist, false); + // Selectivity selec = span_sel_scalar(const_upper, hist_lower, nhist, false); // selec += (1.0 - span_sel_scalar(const_lower, hist_upper, nhist, true)); // selec = 1.0 - selec; - double selec = span_sel_scalar(const_lower, hist_upper, nhist, false); + Selectivity selec = span_sel_scalar(const_lower, hist_upper, nhist, false); selec += (1.0 - span_sel_scalar(const_upper, hist_lower, nhist, true)); selec = 1.0 - selec; return selec; @@ -608,13 +608,13 @@ span_sel_contains(SpanBound *const_lower, SpanBound *const_upper, * @brief Calculate span operator selectivity using histograms of span bounds * @note Used by the selectivity functions */ -static double +static Selectivity span_sel_hist1(AttStatsSlot *hslot, AttStatsSlot *lslot, const Span *constval, meosOper oper) { SpanBound *hist_lower, *hist_upper; SpanBound const_lower, const_upper; - double selec; + Selectivity selec; int nhist, i; /* @@ -687,13 +687,13 @@ span_sel_hist1(AttStatsSlot *hslot, AttStatsSlot *lslot, const Span *constval, selec = span_sel_default(InvalidOid); else { - // elog(NOTICE, "Unable to compute join selectivity for span operator: %d", - // oper); +#if DEBUG_SELECTIVITY + elog(WARNING, "Using default selectivity for operator: %d", oper); +#endif selec = span_sel_default(InvalidOid); } pfree(hist_lower); pfree(hist_upper); - return selec; } @@ -701,12 +701,12 @@ span_sel_hist1(AttStatsSlot *hslot, AttStatsSlot *lslot, const Span *constval, * @brief Calculate span operator selectivity using histograms of span bounds * @note This estimate is for the portion of values that are not NULL */ -double +Selectivity span_sel_hist(VariableStatData *vardata, const Span *constval, meosOper oper, bool value) { AttStatsSlot hslot, lslot; - double selec; + Selectivity selec; memset(&hslot, 0, sizeof(hslot)); @@ -754,8 +754,6 @@ span_sel_hist(VariableStatData *vardata, const Span *constval, meosOper oper, free_attstatsslot(&hslot); if (oper == CONTAINS_OP || oper == CONTAINED_OP) free_attstatsslot(&lslot); - - // elog(WARNING, "Selectivity: %lf", selec); return selec; } @@ -806,7 +804,7 @@ span_const_to_span(Node *other, Span *span) /** * @brief Restriction selectivity for span operators */ -float8 +Selectivity span_sel(PlannerInfo *root, Oid operid, List *args, int varRelid) { VariableStatData vardata; @@ -939,7 +937,7 @@ Span_sel(PG_FUNCTION_ARGS) Oid operid = PG_GETARG_OID(1); List *args = (List *) PG_GETARG_POINTER(2); int varRelid = PG_GETARG_INT32(3); - float8 selec = span_sel(root, operid, args, varRelid); + Selectivity selec = span_sel(root, operid, args, varRelid); PG_RETURN_FLOAT8((float8) selec); } @@ -959,7 +957,6 @@ _mobdb_span_sel(PG_FUNCTION_ARGS) text *att_text = PG_GETARG_TEXT_P(1); Oid operid = PG_GETARG_OID(2); Span *s = PG_GETARG_SPAN_P(3); - float8 selec = 0.0; /* Test input parameters */ char *relname = get_rel_name(relid); @@ -1037,14 +1034,13 @@ _mobdb_span_sel(PG_FUNCTION_ARGS) } } - selec = span_sel_hist1(&hslot, &lslot, s, oper); + Selectivity selec = span_sel_hist1(&hslot, &lslot, s, oper); ReleaseSysCache(stats_tuple); free_attstatsslot(&hslot); if (oper == CONTAINS_OP || oper == CONTAINED_OP) free_attstatsslot(&lslot); - - PG_RETURN_FLOAT8(selec); + PG_RETURN_FLOAT8((float8) selec); } /***************************************************************************** @@ -1101,7 +1097,7 @@ _mobdb_span_sel(PG_FUNCTION_ARGS) * code reuse, since the CDF is computed using the `span_sel_scalar` function, * which is used for restriction (non-join) selectivity estimation. */ -static double +static Selectivity span_joinsel_scalar(const SpanBound *hist1, int nhist1, const SpanBound *hist2, int nhist2, bool equal __attribute__((unused))) { @@ -1115,7 +1111,7 @@ span_joinsel_scalar(const SpanBound *hist1, int nhist1, const SpanBound *hist2, for (j = 0; j < nhist2 && span_bound_cmp(&hist2[j], &hist1[0]) < 0; j++); /* Do the estimation on overlapping regions */ - double selec = 0.0, /* initialisation */ + Selectivity selec = 0.0, /* initialisation */ prev_sel1 = -1.0, /* to skip the first iteration */ prev_sel2 = 0.0; /* make compiler quiet */ while (i < nhist1 && j < nhist2) @@ -1156,7 +1152,7 @@ span_joinsel_scalar(const SpanBound *hist1, int nhist1, const SpanBound *hist2, * @brief Look up the fraction of values in the first histogram that satisfy an * operator with respect to a value in the second histogram */ -static double +static Selectivity span_joinsel_oper(SpanBound *lower1, SpanBound *upper1, int nhist1, SpanBound *lower2, SpanBound *upper2, int nhist2, Datum *length, int length_nvalues, meosOper oper) @@ -1166,7 +1162,7 @@ span_joinsel_oper(SpanBound *lower1, SpanBound *upper1, int nhist1, span_bound_cmp(&lower2[0], &upper1[nhist1 - 1]) > 0) return 0.0; - double selec = 0.0; /* make compiler quiet */ + Selectivity selec = 0.0; /* make compiler quiet */ if (oper == OVERLAPS_OP) { selec = 1.0; @@ -1193,14 +1189,14 @@ span_joinsel_oper(SpanBound *lower1, SpanBound *upper1, int nhist1, /** * @brief Calculate span operator selectivity using histograms of span bounds */ -static double +static Selectivity span_joinsel_hist1(AttStatsSlot *hslot1, AttStatsSlot *hslot2, AttStatsSlot *lslot, meosOper oper) { int nhist1, nhist2; SpanBound *lower1, *upper1, *lower2, *upper2; int i; - double selec; + Selectivity selec; /* * Convert histogram of spans into histograms of its lower and upper @@ -1278,13 +1274,13 @@ span_joinsel_hist1(AttStatsSlot *hslot1, AttStatsSlot *hslot2, selec = span_joinsel_default(InvalidOid); else { - // elog(ERROR, "Unable to compute join selectivity for span operator: %d", - // oper); +#if DEBUG_SELECTIVITY + elog(WARNING, "Using default join selectivity for operator: %d", oper); +#endif selec = span_sel_default(InvalidOid); } pfree(lower1); pfree(upper1); pfree(lower2); pfree(upper2); - return selec; } @@ -1292,14 +1288,14 @@ span_joinsel_hist1(AttStatsSlot *hslot1, AttStatsSlot *hslot2, * @brief Calculate span operator selectivity using histograms of span bounds * @note This estimate is for the portion of values that are not NULL */ -static double +static Selectivity span_joinsel_hist(VariableStatData *vardata1, VariableStatData *vardata2, bool value, meosOper oper) { /* There is only one lslot, see explanation below */ AttStatsSlot hslot1, hslot2, lslot; Form_pg_statistic stats1 = NULL, stats2 = NULL; - double selec; + Selectivity selec; bool have_hist1 = false, have_hist2 = false; int bounds_hist = value ? STATISTIC_KIND_VALUE_BOUNDS_HISTOGRAM : STATISTIC_KIND_TIME_BOUNDS_HISTOGRAM; @@ -1405,9 +1401,6 @@ span_joinsel_hist(VariableStatData *vardata1, VariableStatData *vardata2, free_attstatsslot(&hslot1); free_attstatsslot(&hslot2); if (oper == CONTAINS_OP || oper == CONTAINED_OP) free_attstatsslot(&lslot); - - // elog(WARNING, "Join selectivity: %lf", selec); - return selec; } @@ -1416,7 +1409,7 @@ span_joinsel_hist(VariableStatData *vardata1, VariableStatData *vardata2, /** * @brief Estimate join selectivity for spans */ -float8 +Selectivity span_joinsel(PlannerInfo *root, bool value, meosOper oper, List *args, JoinType jointype __attribute__((unused)), SpecialJoinInfo *sjinfo) { @@ -1426,7 +1419,7 @@ span_joinsel(PlannerInfo *root, bool value, meosOper oper, List *args, &join_is_reversed); /* Estimate join selectivity */ - float8 selec = span_joinsel_hist(&vardata1, &vardata2, value, oper); + Selectivity selec = span_joinsel_hist(&vardata1, &vardata2, value, oper); ReleaseVariableStats(vardata1); ReleaseVariableStats(vardata2); @@ -1483,12 +1476,12 @@ Span_joinsel(PG_FUNCTION_ARGS) PG_RETURN_FLOAT8(span_joinsel_default(operid)); } - float8 selec = span_joinsel(root, value, oper, args, jointype, sjinfo); + Selectivity selec = span_joinsel(root, value, oper, args, jointype, sjinfo); #if DEBUG_SELECTIVITY elog(WARNING, "Join selectivity: %lf, Operator: %s, Left: %s, Right: %s\n", selec, meosoper_name(oper), meostype_name(ltype), meostype_name(rtype)); #endif - PG_RETURN_FLOAT8(selec); + PG_RETURN_FLOAT8((float8) selec); } PGDLLEXPORT Datum _mobdb_span_joinsel(PG_FUNCTION_ARGS); @@ -1506,7 +1499,6 @@ _mobdb_span_joinsel(PG_FUNCTION_ARGS) Oid table2_oid = PG_GETARG_OID(2); text *att2_text = PG_GETARG_TEXT_P(3); Oid operid = PG_GETARG_OID(4); - float8 selec = 0.0; /* Test input parameters */ char *table1_name = get_rel_name(table1_oid); @@ -1618,14 +1610,14 @@ _mobdb_span_joinsel(PG_FUNCTION_ARGS) } /* Compute selectivity */ - selec = span_joinsel_hist1(&hslot1, &hslot2, &lslot, oper); + Selectivity selec = span_joinsel_hist1(&hslot1, &hslot2, &lslot, oper); ReleaseSysCache(stats1_tuple); ReleaseSysCache(stats2_tuple); free_attstatsslot(&hslot1); free_attstatsslot(&hslot2); if (oper == CONTAINS_OP || oper == CONTAINED_OP) free_attstatsslot(&lslot); - PG_RETURN_FLOAT8(selec); + PG_RETURN_FLOAT8((float8) selec); } /*****************************************************************************/ diff --git a/mobilitydb/src/general/temporal_selfuncs.c b/mobilitydb/src/general/temporal_selfuncs.c index 8b386d53d6..8211932cc8 100644 --- a/mobilitydb/src/general/temporal_selfuncs.c +++ b/mobilitydb/src/general/temporal_selfuncs.c @@ -459,7 +459,7 @@ temporal_oper_sel_family(meosOper oper __attribute__((unused)), meosType ltype, Selectivity temporal_sel_tstzspan(VariableStatData *vardata, Span *s, meosOper oper) { - float8 selec; + Selectivity selec; /* * There is no ~= operator for time types and thus it is necessary to @@ -511,12 +511,9 @@ Selectivity tnumber_sel_span_tstzspan(VariableStatData *vardata, Span *span, Span *period, meosOper oper) { - double selec; - Oid value_oprid, tstzspan_oprid; - /* Enable the multiplication of the selectivity of the value and time * dimensions since either may be missing */ - selec = 1.0; + Selectivity selec = 1.0; /* * There is no ~= operator for span/time types and thus it is necessary to @@ -527,7 +524,7 @@ tnumber_sel_span_tstzspan(VariableStatData *vardata, Span *span, Span *period, /* Selectivity for the value dimension */ if (span != NULL) { - value_oprid = oper_oid(EQ_OP, span->spantype, span->spantype); + Oid value_oprid = oper_oid(EQ_OP, span->spantype, span->spantype); #if POSTGRESQL_VERSION_NUMBER < 130000 selec *= var_eq_const(vardata, value_oprid, PointerGetDatum(span), false, false, false); @@ -539,7 +536,7 @@ tnumber_sel_span_tstzspan(VariableStatData *vardata, Span *span, Span *period, /* Selectivity for the time dimension */ if (period != NULL) { - tstzspan_oprid = oper_oid(EQ_OP, period->spantype, period->spantype); + Oid tstzspan_oprid = oper_oid(EQ_OP, period->spantype, period->spantype); #if POSTGRESQL_VERSION_NUMBER < 130000 selec *= var_eq_const(vardata, tstzspan_oprid, SpanPGetDatum(period), false, false, false); @@ -594,7 +591,7 @@ tnumber_sel_span_tstzspan(VariableStatData *vardata, Span *span, Span *period, * @brief Estimate the selectivity value of the operators for temporal types * whose bounding box is a timestamptz span, that is, tbool and ttext */ -float8 +Selectivity temporal_sel(PlannerInfo *root, Oid operid, List *args, int varRelid, TemporalFamily tempfamily) { @@ -752,7 +749,7 @@ temporal_sel(PlannerInfo *root, Oid operid, List *args, int varRelid, * Estimate the restriction selectivity value of the operators for the * various families of temporal types. */ -float8 +Selectivity temporal_sel_family(FunctionCallInfo fcinfo, TemporalFamily tempfamily) { PlannerInfo *root = (PlannerInfo *) PG_GETARG_POINTER(0); @@ -762,8 +759,8 @@ temporal_sel_family(FunctionCallInfo fcinfo, TemporalFamily tempfamily) assert(tempfamily == TEMPORALTYPE || tempfamily == TNUMBERTYPE || tempfamily == TPOINTTYPE || tempfamily == TNPOINTTYPE); - float8 result = temporal_sel(root, operid, args, varRelid, tempfamily); - return result; + Selectivity selec = temporal_sel(root, operid, args, varRelid, tempfamily); + return selec; } PGDLLEXPORT Datum Temporal_sel(PG_FUNCTION_ARGS); @@ -917,7 +914,7 @@ tpoint_joinsel_components(meosOper oper, meosType oprleft, * selectivity for <, <=, >, and >=, while the selectivity functions for * = and <> are eqsel and neqsel, respectively. */ -float8 +Selectivity temporal_joinsel(PlannerInfo *root, Oid operid, List *args, JoinType jointype, SpecialJoinInfo *sjinfo, TemporalFamily tempfamily) { @@ -970,7 +967,7 @@ temporal_joinsel(PlannerInfo *root, Oid operid, List *args, JoinType jointype, /* * Multiply the components of the join selectivity estimation */ - float8 selec = 1.0; + Selectivity selec = 1.0; if (value) { /* @@ -1028,14 +1025,14 @@ temporal_joinsel(PlannerInfo *root, Oid operid, List *args, JoinType jointype, elog(WARNING, "Join selectivity: %lf, Operator: %s, Left: %s, Right: %s\n", selec, meosoper_name(oper), meostype_name(ltype), meostype_name(rtype)); #endif - return (float8) selec; + return selec; } /* * @brief Estimate the join selectivity value of the operators for temporal * alphanumeric types */ -float8 +Selectivity temporal_joinsel_family(FunctionCallInfo fcinfo, TemporalFamily tempfamily) { PlannerInfo *root = (PlannerInfo *) PG_GETARG_POINTER(0); @@ -1052,9 +1049,9 @@ temporal_joinsel_family(FunctionCallInfo fcinfo, TemporalFamily tempfamily) if (jointype != JOIN_INNER) return DEFAULT_TEMP_JOINSEL; - float8 result = temporal_joinsel(root, operid, args, jointype, sjinfo, + Selectivity selec = temporal_joinsel(root, operid, args, jointype, sjinfo, tempfamily); - return result; + return selec; } PGDLLEXPORT Datum Temporal_joinsel(PG_FUNCTION_ARGS); @@ -1066,7 +1063,7 @@ PG_FUNCTION_INFO_V1(Temporal_joinsel); Datum Temporal_joinsel(PG_FUNCTION_ARGS) { - return Float8GetDatum(temporal_joinsel_family(fcinfo, TEMPORALTYPE)); + return Float8GetDatum((float8) temporal_joinsel_family(fcinfo, TEMPORALTYPE)); } PGDLLEXPORT Datum Tnumber_joinsel(PG_FUNCTION_ARGS); @@ -1078,7 +1075,7 @@ PG_FUNCTION_INFO_V1(Tnumber_joinsel); Datum Tnumber_joinsel(PG_FUNCTION_ARGS) { - return Float8GetDatum(temporal_joinsel_family(fcinfo, TNUMBERTYPE)); + return Float8GetDatum((float8) temporal_joinsel_family(fcinfo, TNUMBERTYPE)); } PGDLLEXPORT Datum Tpoint_joinsel(PG_FUNCTION_ARGS); @@ -1090,7 +1087,7 @@ PG_FUNCTION_INFO_V1(Tpoint_joinsel); Datum Tpoint_joinsel(PG_FUNCTION_ARGS) { - return Float8GetDatum(temporal_joinsel_family(fcinfo, TPOINTTYPE)); + return Float8GetDatum((float8) temporal_joinsel_family(fcinfo, TPOINTTYPE)); } PGDLLEXPORT Datum Tnpoint_joinsel(PG_FUNCTION_ARGS); @@ -1102,7 +1099,7 @@ PG_FUNCTION_INFO_V1(Tnpoint_joinsel); Datum Tnpoint_joinsel(PG_FUNCTION_ARGS) { - return Float8GetDatum(temporal_joinsel_family(fcinfo, TNPOINTTYPE)); + return Float8GetDatum((float8) temporal_joinsel_family(fcinfo, TNPOINTTYPE)); } /*****************************************************************************/ diff --git a/mobilitydb/src/npoint/tnpoint_gin.c b/mobilitydb/src/npoint/tnpoint_gin.c index d011aa5356..de9441447d 100644 --- a/mobilitydb/src/npoint/tnpoint_gin.c +++ b/mobilitydb/src/npoint/tnpoint_gin.c @@ -75,9 +75,9 @@ Tnpoint_gin_extract_value(PG_FUNCTION_ARGS) Datum *elems = palloc(sizeof(Datum) * routes->count); for (int i = 0; i < routes->count; i++) elems[i] = Int64GetDatum(SET_VAL_N(routes, i)); - pfree(routes); *nkeys = routes->count; *nullFlags = NULL; + pfree(routes); PG_FREE_IF_COPY(temp, 0); PG_RETURN_POINTER(elems); } @@ -127,9 +127,9 @@ Tnpoint_gin_extract_query(PG_FUNCTION_ARGS) elems = palloc(sizeof(Datum) * routes->count); for (int i = 0; i < routes->count; i++) elems[i] = Int64GetDatum(SET_VAL_N(routes, i)); - pfree(routes); *nkeys = routes->count; *searchMode = GIN_SEARCH_MODE_DEFAULT; + pfree(routes); PG_FREE_IF_COPY(temp, 0); break; default: diff --git a/mobilitydb/src/point/tpoint_selfuncs.c b/mobilitydb/src/point/tpoint_selfuncs.c index b12d1d6552..0fd25a0d45 100644 --- a/mobilitydb/src/point/tpoint_selfuncs.c +++ b/mobilitydb/src/point/tpoint_selfuncs.c @@ -485,13 +485,13 @@ nd_box_from_stbox(const STBox *box, ND_BOX *nd_box) * @note This function generalizes PostGIS function estimate_selectivity in * file gserialized_estimate.c */ -float8 +Selectivity geo_sel(VariableStatData *vardata, const STBox *box, meosOper oper) { ND_STATS *nd_stats; AttStatsSlot sslot; int d; /* counter */ - float8 selec; + Selectivity selec; ND_BOX nd_box; ND_IBOX nd_ibox, search_ibox; int at[ND_DIMS]; diff --git a/postgis/liblwgeom/lwhomogenize.c b/postgis/liblwgeom/lwhomogenize.c index 70c39e9ee4..ac20ab7a78 100644 --- a/postgis/liblwgeom/lwhomogenize.c +++ b/postgis/liblwgeom/lwhomogenize.c @@ -101,7 +101,7 @@ lwcollection_build_buffer(const LWCOLLECTION *col, HomogenizeBuffer *buffer) buffer->buf[geom->type] = bufcol; } /* Add sub-geom to buffer */ - lwcollection_add_lwgeom(buffer->buf[geom->type], lwgeom_clone(geom)); + lwcollection_add_lwgeom(buffer->buf[geom->type], lwgeom_clone_deep(geom)); /* Increment count for this singleton type */ buffer->cnt[geom->type]++; break; @@ -217,7 +217,7 @@ lwgeom_homogenize(const LWGEOM *geom) return lwcollection_as_lwgeom(lwcollection_construct_empty(geom->type, geom->srid, lwgeom_has_z(geom), lwgeom_has_m(geom))); } - return lwgeom_clone(geom); + return lwgeom_clone_deep(geom); } switch (geom->type) @@ -231,7 +231,7 @@ lwgeom_homogenize(const LWGEOM *geom) case TRIANGLETYPE: case CURVEPOLYTYPE: case POLYGONTYPE: - return lwgeom_clone(geom); + return lwgeom_clone_deep(geom); /* Process homogeneous geometries lightly */ case MULTIPOINTTYPE: @@ -247,7 +247,6 @@ lwgeom_homogenize(const LWGEOM *geom) /* Strip single-entry multi-geometries down to singletons */ if ( col->ngeoms == 1 ) { - // hgeom = lwgeom_clone((LWGEOM*)(col->geoms[0])); // MobilityDB changed hgeom = lwgeom_clone_deep((LWGEOM*)(col->geoms[0])); hgeom->srid = geom->srid; if (geom->bbox) @@ -256,7 +255,7 @@ lwgeom_homogenize(const LWGEOM *geom) } /* Return proper multigeometry untouched */ - return lwgeom_clone(geom); + return lwgeom_clone_deep(geom); } /* Work on anonymous collections separately */