@@ -455,7 +455,8 @@ jsonPathStatsGetArrayIndexSelectivity(JsonPathStats pstats, int index)
455
455
* 'path' is an array of text datums of length 'pathlen' (can be zero).
456
456
*/
457
457
static JsonPathStats
458
- jsonStatsGetPath (JsonStats jsdata , Datum * path , int pathlen , float4 * nullfrac )
458
+ jsonStatsGetPath (JsonStats jsdata , Datum * path , int pathlen ,
459
+ bool try_arrays_indexes , float4 * nullfrac )
459
460
{
460
461
JsonPathStats pstats = jsonStatsGetRootPath (jsdata );
461
462
Selectivity sel = 1.0 ;
@@ -466,6 +467,14 @@ jsonStatsGetPath(JsonStats jsdata, Datum *path, int pathlen, float4 *nullfrac)
466
467
char * tail ;
467
468
int index ;
468
469
470
+ if (!try_arrays_indexes )
471
+ {
472
+ /* Find object key stats */
473
+ pstats = jsonPathStatsGetSubpath (pstats , key );
474
+ pfree (key );
475
+ continue ;
476
+ }
477
+
469
478
/* Try to interpret path entry as integer array index */
470
479
errno = 0 ;
471
480
index = strtoint (key , & tail , 10 );
@@ -939,14 +948,15 @@ jsonPathStatsFormTuple(JsonPathStats pstats, JsonStatType type, float4 nullfrac)
939
948
940
949
/*
941
950
* jsonStatsGetPathTuple
942
- * Extract JSON statistics for a path and form pg_statistics tuple.
951
+ * Extract JSON statistics for a text[] path and form pg_statistics tuple.
943
952
*/
944
953
static HeapTuple
945
954
jsonStatsGetPathTuple (JsonStats jsdata , JsonStatType type ,
946
- Datum * path , int pathlen )
955
+ Datum * path , int pathlen , bool try_arrays_indexes )
947
956
{
948
957
float4 nullfrac ;
949
- JsonPathStats pstats = jsonStatsGetPath (jsdata , path , pathlen , & nullfrac );
958
+ JsonPathStats pstats = jsonStatsGetPath (jsdata , path , pathlen ,
959
+ try_arrays_indexes , & nullfrac );
950
960
951
961
return jsonPathStatsFormTuple (pstats , type , nullfrac );
952
962
}
@@ -1030,8 +1040,9 @@ jsonbStatsVarOpConst(Oid opid, VariableStatData *resdata,
1030
1040
return false;
1031
1041
}
1032
1042
1033
- resdata -> statsTuple =
1034
- jsonStatsGetPathTuple (& jsdata , statype , & cnst -> constvalue , 1 );
1043
+ resdata -> statsTuple = jsonStatsGetPathTuple (& jsdata , statype ,
1044
+ & cnst -> constvalue , 1 ,
1045
+ false);
1035
1046
break ;
1036
1047
}
1037
1048
@@ -1081,8 +1092,9 @@ jsonbStatsVarOpConst(Oid opid, VariableStatData *resdata,
1081
1092
}
1082
1093
1083
1094
if (!have_nulls )
1084
- resdata -> statsTuple =
1085
- jsonStatsGetPathTuple (& jsdata , statype , path , pathlen );
1095
+ resdata -> statsTuple = jsonStatsGetPathTuple (& jsdata , statype ,
1096
+ path , pathlen ,
1097
+ true);
1086
1098
1087
1099
pfree (path );
1088
1100
pfree (nulls );
@@ -1431,7 +1443,7 @@ jsonSelectivityExists(JsonStats stats, Datum key)
1431
1443
1432
1444
jbkey = JsonbPGetDatum (JsonbValueToJsonb (& jbvkey ));
1433
1445
1434
- keysel = jsonStatsGetPathFreq (stats , & key , 1 );
1446
+ keysel = jsonStatsGetPathFreq (stats , & key , 1 , false );
1435
1447
1436
1448
rootstats = jsonStatsGetRootPath (stats );
1437
1449
scalarsel = jsonSelectivity (rootstats , jbkey , JsonbEqOperator );
0 commit comments