PostgreSQL Source Code
git master
|
#include "postgres.h"
#include "catalog/pg_collation.h"
#include "common/hashfn.h"
#include "miscadmin.h"
#include "port/pg_bitutils.h"
#include "utils/datetime.h"
#include "utils/fmgrprotos.h"
#include "utils/json.h"
#include "utils/jsonb.h"
#include "utils/memutils.h"
#include "utils/varlena.h"
Go to the source code of this file.
Macros | |
#define | JSONB_MAX_ELEMS (Min(MaxAllocSize / sizeof(JsonbValue), JB_CMASK)) |
#define | JSONB_MAX_PAIRS (Min(MaxAllocSize / sizeof(JsonbPair), JB_CMASK)) |
#define JSONB_MAX_ELEMS (Min(MaxAllocSize / sizeof(JsonbValue), JB_CMASK)) |
Definition at line 36 of file jsonb_util.c.
#define JSONB_MAX_PAIRS (Min(MaxAllocSize / sizeof(JsonbPair), JB_CMASK)) |
Definition at line 37 of file jsonb_util.c.
|
static |
Definition at line 788 of file jsonb_util.c.
References Assert, JsonbParseState::contVal, ereport, errcode(), errmsg(), ERROR, jbvArray, JSONB_MAX_ELEMS, repalloc(), JsonbParseState::size, JsonbValue::type, and JsonbValue::val.
Referenced by pushJsonbValueScalar().
|
static |
Definition at line 746 of file jsonb_util.c.
References Assert, JsonbParseState::contVal, ereport, errcode(), errmsg(), ERROR, jbvObject, jbvString, JSONB_MAX_PAIRS, repalloc(), JsonbParseState::size, JsonbValue::type, and JsonbValue::val.
Referenced by pushJsonbValueScalar().
|
static |
Definition at line 1513 of file jsonb_util.c.
References copyToBuffer(), data, len, and reserveFromBuffer().
Referenced by convertJsonbArray(), convertJsonbObject(), and convertJsonbScalar().
|
static |
Definition at line 775 of file jsonb_util.c.
References Assert, JsonbParseState::contVal, jbvObject, and JsonbValue::type.
Referenced by pushJsonbValueScalar().
int compareJsonbContainers | ( | JsonbContainer * | a, |
JsonbContainer * | b | ||
) |
Definition at line 191 of file jsonb_util.c.
References a, Assert, b, compareJsonbScalarValue(), elog, ERROR, i, jbvArray, jbvBinary, jbvBool, jbvDatetime, jbvNull, jbvNumeric, jbvObject, jbvString, JsonbIteratorInit(), JsonbIteratorNext(), JsonbIterator::parent, pfree(), res, JsonbValue::type, JsonbValue::val, WJB_DONE, WJB_END_ARRAY, and WJB_END_OBJECT.
Referenced by jsonb_cmp(), jsonb_eq(), jsonb_ge(), jsonb_gt(), jsonb_le(), jsonb_lt(), and jsonb_ne().
|
static |
Definition at line 1433 of file jsonb_util.c.
References a, b, DatumGetInt32(), DirectFunctionCall2, elog, ERROR, jbvBool, jbvNull, jbvNumeric, jbvString, numeric_cmp(), PointerGetDatum(), and varstr_cmp().
Referenced by compareJsonbContainers().
|
static |
Definition at line 1615 of file jsonb_util.c.
References appendToBuffer(), Assert, convertJsonbValue(), copyToBuffer(), ereport, errcode(), errmsg(), ERROR, i, JB_FARRAY, JB_FSCALAR, JB_OFFSET_STRIDE, JBE_OFFLENFLD, JENTRY_HAS_OFF, JENTRY_ISCONTAINER, JENTRY_OFFLENMASK, JENTRY_TYPEMASK, StringInfoData::len, len, padBufferToInt(), reserveFromBuffer(), and val.
Referenced by convertJsonbValue().
|
static |
Definition at line 1699 of file jsonb_util.c.
References appendToBuffer(), convertJsonbScalar(), convertJsonbValue(), copyToBuffer(), ereport, errcode(), errmsg(), ERROR, i, JB_FOBJECT, JB_OFFSET_STRIDE, JBE_OFFLENFLD, JENTRY_HAS_OFF, JENTRY_ISCONTAINER, JENTRY_OFFLENMASK, JENTRY_TYPEMASK, JsonbPair::key, StringInfoData::len, len, padBufferToInt(), reserveFromBuffer(), val, and JsonbPair::value.
Referenced by convertJsonbValue().
|
static |
Definition at line 1815 of file jsonb_util.c.
References appendToBuffer(), buf, elog, ERROR, jbvBool, jbvDatetime, jbvNull, jbvNumeric, jbvString, JENTRY_ISBOOL_FALSE, JENTRY_ISBOOL_TRUE, JENTRY_ISNULL, JENTRY_ISNUMERIC, JsonEncodeDateTime(), len, MAXDATELEN, padBufferToInt(), JsonbValue::type, JsonbValue::val, and VARSIZE_ANY.
Referenced by convertJsonbObject(), and convertJsonbValue().
|
static |
Definition at line 1590 of file jsonb_util.c.
References check_stack_depth(), convertJsonbArray(), convertJsonbObject(), convertJsonbScalar(), elog, ERROR, IsAJsonbScalar, jbvArray, jbvObject, and val.
Referenced by convertJsonbArray(), convertJsonbObject(), and convertToJsonb().
|
static |
Definition at line 1548 of file jsonb_util.c.
References Assert, convertJsonbValue(), StringInfoData::data, initStringInfo(), jbvBinary, StringInfoData::len, res, reserveFromBuffer(), SET_VARSIZE, val, and VARHDRSZ.
Referenced by JsonbValueToJsonb().
|
static |
Definition at line 1504 of file jsonb_util.c.
References StringInfoData::data, data, and len.
Referenced by appendToBuffer(), convertJsonbArray(), and convertJsonbObject().
|
static |
Definition at line 1401 of file jsonb_util.c.
References a, b, DatumGetBool(), DirectFunctionCall2, elog, ERROR, jbvBool, jbvNull, jbvNumeric, jbvString, lengthCompareJsonbStringValue(), numeric_eq(), and PointerGetDatum().
Referenced by findJsonbValueFromContainer(), and JsonbDeepContains().
|
static |
Definition at line 505 of file jsonb_util.c.
References Assert, JsonbContainer::children, getJsonbLength(), INTALIGN, JBE_ISBOOL_FALSE, JBE_ISBOOL_TRUE, JBE_ISCONTAINER, JBE_ISNULL, JBE_ISNUMERIC, JBE_ISSTRING, jbvBinary, jbvBool, jbvNull, jbvNumeric, jbvString, JsonbValue::type, and JsonbValue::val.
Referenced by findJsonbValueFromContainer(), getIthJsonbValueFromContainer(), getKeyJsonValueFromContainer(), and JsonbIteratorNext().
JsonbValue* findJsonbValueFromContainer | ( | JsonbContainer * | container, |
uint32 | flags, | ||
JsonbValue * | key | ||
) |
Definition at line 344 of file jsonb_util.c.
References Assert, JsonbContainer::children, equalsJsonbScalarValue(), fillJsonbValue(), getKeyJsonValueFromContainer(), i, JB_FARRAY, JB_FOBJECT, JBE_ADVANCE_OFFSET, jbvString, JsonContainerIsArray, JsonContainerIsObject, JsonContainerSize, sort-test::key, palloc(), pfree(), and JsonbValue::type.
Referenced by executeItemOptUnwrapTarget(), getJsonPathVariableFromJsonb(), jsonb_exists(), jsonb_exists_all(), jsonb_exists_any(), and JsonbDeepContains().
|
static |
Definition at line 1041 of file jsonb_util.c.
References JsonbIterator::parent, and pfree().
Referenced by JsonbIteratorNext().
JsonbValue* getIthJsonbValueFromContainer | ( | JsonbContainer * | container, |
uint32 | i | ||
) |
Definition at line 468 of file jsonb_util.c.
References JsonbContainer::children, elog, ERROR, fillJsonbValue(), getJsonbOffset(), i, if(), JsonContainerIsArray, JsonContainerSize, and palloc().
Referenced by executeItemOptUnwrapTarget(), jsonb_array_element(), jsonb_array_element_text(), and jsonb_get_element().
uint32 getJsonbLength | ( | const JsonbContainer * | jc, |
int | index | ||
) |
Definition at line 159 of file jsonb_util.c.
References JsonbContainer::children, getJsonbOffset(), JBE_HAS_OFF, JBE_OFFLENFLD, and len.
Referenced by fillJsonbValue(), and getKeyJsonValueFromContainer().
uint32 getJsonbOffset | ( | const JsonbContainer * | jc, |
int | index | ||
) |
Definition at line 134 of file jsonb_util.c.
References JsonbContainer::children, i, JBE_HAS_OFF, and JBE_OFFLENFLD.
Referenced by getIthJsonbValueFromContainer(), getJsonbLength(), getKeyJsonValueFromContainer(), and JsonbIteratorNext().
JsonbValue* getKeyJsonValueFromContainer | ( | JsonbContainer * | container, |
const char * | keyVal, | ||
int | keyLen, | ||
JsonbValue * | res | ||
) |
Definition at line 398 of file jsonb_util.c.
References Assert, JsonbContainer::children, difference(), fillJsonbValue(), getJsonbLength(), getJsonbOffset(), JsonContainerIsObject, JsonContainerSize, lengthCompareJsonbString(), palloc(), and res.
Referenced by findJsonbValueFromContainer(), JsObjectGetField(), jsonb_get_element(), jsonb_object_field(), jsonb_object_field_text(), and JsonbDeepContains().
|
static |
Definition at line 999 of file jsonb_util.c.
References Assert, JsonbContainer::children, JsonbIterator::children, JsonbIterator::container, JsonbIterator::dataProper, elog, ERROR, JsonbContainer::header, JsonbIterator::isScalar, JB_FARRAY, JB_FOBJECT, JBI_ARRAY_START, JBI_OBJECT_START, JsonContainerIsScalar, JsonContainerSize, JsonbIterator::nElems, palloc0(), JsonbIterator::parent, and JsonbIterator::state.
Referenced by JsonbIteratorInit(), and JsonbIteratorNext().
bool JsonbDeepContains | ( | JsonbIterator ** | val, |
JsonbIterator ** | mContained | ||
) |
Definition at line 1062 of file jsonb_util.c.
References Assert, check_stack_depth(), elog, equalsJsonbScalarValue(), ERROR, findJsonbValueFromContainer(), getKeyJsonValueFromContainer(), i, IsAJsonbScalar, j, JB_FARRAY, jbvArray, jbvBinary, jbvObject, jbvString, JsonbIteratorInit(), JsonbIteratorNext(), palloc(), pfree(), JsonbValue::type, JsonbValue::val, val, WJB_BEGIN_ARRAY, WJB_BEGIN_OBJECT, WJB_ELEM, WJB_END_ARRAY, WJB_END_OBJECT, WJB_KEY, and WJB_VALUE.
Referenced by jsonb_contained(), and jsonb_contains().
void JsonbHashScalarValue | ( | const JsonbValue * | scalarVal, |
uint32 * | hash | ||
) |
Definition at line 1316 of file jsonb_util.c.
References DatumGetUInt32(), DirectFunctionCall1, elog, ERROR, hash(), hash_any(), hash_numeric(), jbvBool, jbvNull, jbvNumeric, jbvString, NumericGetDatum(), pg_rotate_left32(), JsonbValue::type, and JsonbValue::val.
Referenced by gin_extract_jsonb_path(), jsonb_hash(), jsonb_path_ops__add_path_item(), and jsonb_path_ops__extract_nodes().
void JsonbHashScalarValueExtended | ( | const JsonbValue * | scalarVal, |
uint64 * | hash, | ||
uint64 | seed | ||
) |
Definition at line 1359 of file jsonb_util.c.
References BoolGetDatum(), DatumGetUInt64(), DirectFunctionCall2, elog, ERROR, hash(), hash_any_extended(), hash_numeric_extended(), hashcharextended(), jbvBool, jbvNull, jbvNumeric, jbvString, NumericGetDatum(), ROTATE_HIGH_AND_LOW_32BITS, JsonbValue::type, UInt64GetDatum(), and JsonbValue::val.
Referenced by jsonb_hash_extended().
JsonbIterator* JsonbIteratorInit | ( | JsonbContainer * | container | ) |
Definition at line 817 of file jsonb_util.c.
References iteratorFromContainer().
Referenced by compareJsonbContainers(), datum_to_jsonb_internal(), each_worker_jsonb(), elements_worker_jsonb(), executeAnyItem(), executeKeyValueMethod(), gin_extract_jsonb(), gin_extract_jsonb_path(), iterate_jsonb_values(), jsonb_agg_transfn_worker(), jsonb_concat(), jsonb_contained(), jsonb_contains(), jsonb_delete(), jsonb_delete_array(), jsonb_delete_idx(), jsonb_delete_path(), jsonb_hash(), jsonb_hash_extended(), jsonb_insert(), jsonb_object_agg_transfn_worker(), jsonb_object_keys(), jsonb_set(), jsonb_set_element(), jsonb_strip_nulls(), Jsonb_to_SV(), JsonbDeepContains(), JsonbExtractScalar(), JsonbToCStringWorker(), parse_jsonb_index_flags(), PLyObject_FromJsonbContainer(), populate_array_dim_jsonb(), populate_recordset_worker(), pushJsonbValue(), and transform_jsonb_string_values().
JsonbIteratorToken JsonbIteratorNext | ( | JsonbIterator ** | it, |
JsonbValue * | val, | ||
bool | skipNested | ||
) |
Definition at line 853 of file jsonb_util.c.
References elog, ERROR, fillJsonbValue(), freeAndGetParent(), getJsonbOffset(), IsAJsonbScalar, iteratorFromContainer(), JBE_ADVANCE_OFFSET, JBI_ARRAY_ELEM, JBI_ARRAY_START, JBI_OBJECT_KEY, JBI_OBJECT_START, JBI_OBJECT_VALUE, jbvArray, jbvObject, jbvString, val, WJB_BEGIN_ARRAY, WJB_BEGIN_OBJECT, WJB_DONE, WJB_ELEM, WJB_END_ARRAY, WJB_END_OBJECT, WJB_KEY, and WJB_VALUE.
Referenced by compareJsonbContainers(), datum_to_jsonb_internal(), each_worker_jsonb(), elements_worker_jsonb(), executeAnyItem(), executeKeyValueMethod(), gin_extract_jsonb(), gin_extract_jsonb_path(), iterate_jsonb_values(), IteratorConcat(), jsonb_agg_transfn_worker(), jsonb_delete(), jsonb_delete_array(), jsonb_delete_idx(), jsonb_hash(), jsonb_hash_extended(), jsonb_object_agg_transfn_worker(), jsonb_object_keys(), jsonb_strip_nulls(), Jsonb_to_SV(), JsonbDeepContains(), JsonbExtractScalar(), JsonbToCStringWorker(), parse_jsonb_index_flags(), PLyObject_FromJsonbContainer(), populate_array_dim_jsonb(), populate_recordset_worker(), pushJsonbValue(), setPath(), setPathArray(), setPathObject(), and transform_jsonb_string_values().
void JsonbToJsonbValue | ( | Jsonb * | jsonb, |
JsonbValue * | val | ||
) |
Definition at line 72 of file jsonb_util.c.
References jbvBinary, Jsonb::root, val, VARHDRSZ, and VARSIZE.
Referenced by jsonb_insert(), jsonb_set(), and jsonb_subscript_assign().
Jsonb* JsonbValueToJsonb | ( | JsonbValue * | val | ) |
Definition at line 92 of file jsonb_util.c.
References Assert, convertToJsonb(), IsAJsonbScalar, jbvArray, jbvBinary, jbvObject, palloc(), pushJsonbValue(), res, SET_VARSIZE, JsonbValue::type, JsonbValue::val, val, VARDATA, VARHDRSZ, WJB_BEGIN_ARRAY, WJB_ELEM, and WJB_END_ARRAY.
Referenced by datum_to_jsonb(), each_worker_jsonb(), elements_worker_jsonb(), ExecEvalJsonExprPath(), ExecGetJsonValueItemString(), executeKeyValueMethod(), hstore_to_jsonb(), hstore_to_jsonb_loose(), jsonb_agg_finalfn(), jsonb_agg_transfn_worker(), jsonb_array_element(), jsonb_build_array_noargs(), jsonb_build_array_worker(), jsonb_build_object_noargs(), jsonb_build_object_worker(), jsonb_concat(), jsonb_delete(), jsonb_delete_array(), jsonb_delete_idx(), jsonb_delete_path(), jsonb_from_cstring(), jsonb_get_element(), jsonb_insert(), jsonb_object(), jsonb_object_agg_finalfn(), jsonb_object_agg_transfn_worker(), jsonb_object_field(), jsonb_object_two_arg(), jsonb_path_query_array_internal(), jsonb_path_query_first_internal(), jsonb_path_query_internal(), jsonb_set(), jsonb_set_element(), jsonb_strip_nulls(), jsonb_subscript_assign(), JsonPathQuery(), JsonTablePlanScanNextRow(), plperl_to_jsonb(), plpython_to_jsonb(), populate_scalar(), and transform_jsonb_string_values().
|
static |
Definition at line 1919 of file jsonb_util.c.
References a, b, JsonbPair::key, lengthCompareJsonbStringValue(), JsonbPair::order, and res.
Referenced by uniqueifyJsonbObject().
|
static |
Definition at line 1899 of file jsonb_util.c.
Referenced by getKeyJsonValueFromContainer(), and lengthCompareJsonbStringValue().
|
static |
Definition at line 1880 of file jsonb_util.c.
References a, Assert, b, jbvString, lengthCompareJsonbString(), JsonbValue::type, and JsonbValue::val.
Referenced by equalsJsonbScalarValue(), lengthCompareJsonbPair(), and uniqueifyJsonbObject().
|
static |
Definition at line 1527 of file jsonb_util.c.
References StringInfoData::data, INTALIGN, StringInfoData::len, and reserveFromBuffer().
Referenced by convertJsonbArray(), convertJsonbObject(), and convertJsonbScalar().
JsonbValue* pushJsonbValue | ( | JsonbParseState ** | pstate, |
JsonbIteratorToken | seq, | ||
JsonbValue * | jbval | ||
) |
Definition at line 566 of file jsonb_util.c.
References Assert, i, JB_FSCALAR, jbvArray, jbvBinary, jbvObject, JsonbIteratorInit(), JsonbIteratorNext(), pushJsonbValueScalar(), res, JsonbValue::type, JsonbValue::val, WJB_BEGIN_ARRAY, WJB_BEGIN_OBJECT, WJB_DONE, WJB_ELEM, WJB_END_ARRAY, WJB_END_OBJECT, WJB_KEY, and WJB_VALUE.
Referenced by array_dim_to_jsonb(), array_to_jsonb_internal(), AV_to_JsonbValue(), composite_to_jsonb(), datum_to_jsonb_internal(), executeKeyValueMethod(), hstore_to_jsonb(), hstore_to_jsonb_loose(), HV_to_JsonbValue(), IteratorConcat(), jsonb_agg_finalfn(), jsonb_agg_transfn_worker(), jsonb_build_array_noargs(), jsonb_build_array_worker(), jsonb_build_object_noargs(), jsonb_build_object_worker(), jsonb_delete(), jsonb_delete_array(), jsonb_delete_idx(), jsonb_in_array_end(), jsonb_in_array_start(), jsonb_in_object_end(), jsonb_in_object_field_start(), jsonb_in_object_start(), jsonb_in_scalar(), jsonb_object(), jsonb_object_agg_finalfn(), jsonb_object_agg_transfn_worker(), jsonb_object_two_arg(), jsonb_strip_nulls(), JsonbValueToJsonb(), PLyMapping_ToJsonbValue(), PLyObject_ToJsonbValue(), PLySequence_ToJsonbValue(), push_null_elements(), push_path(), setPath(), setPathArray(), setPathObject(), SV_to_JsonbValue(), transform_jsonb_string_values(), and wrapItemsInArray().
|
static |
Definition at line 640 of file jsonb_util.c.
References appendElement(), appendKey(), appendValue(), Assert, elog, ERROR, IsAJsonbScalar, jbvArray, jbvObject, jbvString, JsonbParseState::next, palloc(), pushState(), JsonbValue::type, uniqueifyJsonbObject(), JsonbValue::val, WJB_BEGIN_ARRAY, WJB_BEGIN_OBJECT, WJB_ELEM, WJB_END_ARRAY, WJB_END_OBJECT, WJB_KEY, and WJB_VALUE.
Referenced by pushJsonbValue().
|
static |
Definition at line 731 of file jsonb_util.c.
References JsonbParseState::next, palloc(), JsonbParseState::skip_nulls, and JsonbParseState::unique_keys.
Referenced by pushJsonbValueScalar().
|
static |
Definition at line 1478 of file jsonb_util.c.
References StringInfoData::data, enlargeStringInfo(), StringInfoData::len, and len.
Referenced by appendToBuffer(), convertJsonbArray(), convertJsonbObject(), convertToJsonb(), and padBufferToInt().
|
static |
Definition at line 1943 of file jsonb_util.c.
References Assert, ereport, errcode(), errmsg(), ERROR, jbvNull, jbvObject, lengthCompareJsonbPair(), lengthCompareJsonbStringValue(), qsort_arg(), res, JsonbValue::type, JsonbValue::val, and JsonbPair::value.
Referenced by pushJsonbValueScalar().